git的安装与初配置

版权声明:本文为博主原创文章! github地址:https://github.com/lina-not-linus;简书:https://www.jianshu.com/u/516d28ccd858;博客: https://blog.csdn.net/Lina_ACM/article/details/79707791

一. 初次安装git后后配置用户名与邮箱:

# 注意:引号内请输入你自己设置的名字,和你自己的邮箱,
# 此用户名和邮箱是git提交代码时用来显示你身份和联系方式的,
# 并不是github用户名和邮箱
git config --global user.name "yourname"
git congig --global user.email "[email protected]"

二. git使用ssh密钥:

 1. 生成密钥对
 2. 添加公钥到你的远程仓库(github)
 3. 修改git的 remote url
  • 生成密钥对:
    git服务器一般是选用使用ssh公钥进行授权,系统中的每一个用户都必须提供
    一个公钥用于授权。ssh公钥默认存储在本用户下的~/.ssh目录:id_dsa,
    与id_.dsa.pub文件,或者是rsa的,其中以.pub后缀的是公钥文件,
    另外一个就是私钥文件。
# 使用sshkeygen创建
 ssh-keygen -t rsa -C "[email protected]"
  • 添加公钥到你的远程仓库(github)
# 查看ssh-keygen创建好的公钥
 cat ~/.ssh/id_rsa.pub
# 登陆你的github帐户。点击你的头像,然后
 Settings -> 左栏点击 SSH and GPG keys -> 点击 New SSH key
# 然后你复制上面cat出来的的公钥内容,粘贴进“Key”文本域内。
# title里的内容,起一个自己区分的名字,点击Add key
#最后验证添加的key是否正常工作:
 ssh -T [email protected]
  • 修改git的 remote url
# 首先查看remote 当前的remote的ssh-url或者http
 git remote -v
# 增加remote url
 git remote add origin(自己设置的name) ssh-url-address(url地址)
# 删除remote url
 git remote rm origin(想要删除哪一个ssh-url-address就写它的名)

自此可以直接的使用git push,git fetch,git pull,就不需要烦人的密码输入了,但假如你没加公钥(或不成功放入)到github的key亦或者你加入remote的是http,那最后还是需要输入用户名和密码的。

猜你喜欢

转载自blog.csdn.net/Lina_ACM/article/details/79707791
今日推荐