更加方便的使用git上传自己的代码

经过以上的培训,同学们肯定对git的基本使用没有什么问题了。但是每次代码有更改后,依旧需要

git  add  *

git  commit * git   打开vim编辑器,编辑提交信息

或者 git  commit   *  -m  "提交信息“

git   push  时,需要输入用户名和密码

可以有两种解决方法:

一、生成ssh key,过程如下:

$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/munication/.ssh/id_rsa): 直接按下回车,
Created directory '/home/munication/.ssh'. 将key保存到默认的位置
Enter passphrase (empty for no passphrase): 输入自己的密码例如lisan
Enter same passphrase again:  重复输入刚才一样的密码
Your identification has been saved in /home/munication/.ssh/id_rsa.
Your public key has been saved in /home/munication/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:CfxwbPFh45ZCG/qixBUxqXwOlD1Gedk9RAqIZAIXYZQ munication@develop
The key's randomart image is:
+---[RSA 3072]----+
|.oB=o====o++o    |
| oEo+.B*oO.=o    |
|   o o*o* *  .   |
|   .+..B +       |
|    o+. S        |
|   . ...         |
|    .            |
|                 |
|                 |
+----[SHA256]-----+

二、将ssh key添加到github上,到 https://github.com/settings/keys中SSH and GPG keys中的new SSH key按钮,将
'/home/munication/.ssh'中的有pub字样的文件内容,粘贴保存即可。
三、 设置ssh key后push为什么还要输入用户名和密码

  因为你用的是https而不是ssh。 你可以更新一下origin

  git remote remove origin
  git remote add origin git@github.com:guochaoxxl/18DataStruct.git

  之后你还需要重新设置分支,比如:

  git push --set-upstream origin master
四、设置下提交,这次不需要密码了,也不需要用户名了。

五、其实使用GPG key是差不多一样的步骤。不再多说了。

转载:https://www.cnblogs.com/xueweihan/p/5430451.html

GPG是一种加密算法,现在github支持commit使用GPG加密,从而保证提交的commit在传输的过程中没有被篡改。

一、生成GPG密钥

什么是GPG:阮一峰的GPG教程

  1. 安装GPG:brew install GPG

  2. 生成GPG key:gpg --gen-key,根据提示,生成GPG key,注意:确保邮箱的那项是你github账号认证的邮箱;还有记住输入的密码。

  3. 查看GPG key:gpg --list-keys,如下图:

    注意:sub:私钥;pub:公钥;黄色的才是GPG key ID

  4. 获取公钥:gpg --armor --export pub GPG key ID

二、github设置GPG key

  1. 拷贝上面得到的公钥到github账号中,注意:格式如:开头:-----BEGIN PGP PUBLIC KEY BLOCK-----,结尾:-----END PGP PUBLIC KEY BLOCK-----。请参考把GPG key 加到你的github帐号

三、配置git

  1. 通过:gpg --list-keys查看pub GPG key ID,然后设置git签名时用的key:git config --global user.signingkey pub GPG key ID

  2. 开启GPG签名commit:git config commit.gpgsign true;关闭:git config commit.gpgsign false

  3. 如果你想让所有的本地仓库都使用GPG签名:git config --global commit.gpgsign true

四、效果

和正常的提交commit的区别,在开启commit使用GPG加密后,提交commit时,如下图:

push到github效果如下:

猜你喜欢

转载自www.cnblogs.com/guochaoxxl/p/11695033.html