Linux(Centos 7)下安装Git并配置连接GitHub

1、安装git  Centos7 查看git --version 

2、配置用户名密码

git config --global user.name "xxx"
git config --global user.email "xxx@gmail.com"

3、为GitHub账号添加SSH Keys
ssh-keygen -t rsa -C "qiubing.it@gmail.com" 生成key
系统会提示key的保存位置(一般是~/.ssh目录)和指定口令,保持默认,连续三次回车即可

  1. 复制SSH Key到GITHUB

打开该文件,id_rsa.pub文件内的内容,粘帖到github帐号管理的添加SSH key界面中

cat ~/.ssh/id_rsa.pub

登录github-> Settings-> SSH and GPG Keys-> New SSH key添加

  1. 测试是否连接成功
ssh -T git@github.com

会提示

The authenticity of host 'github.com (192.30.255.112)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes

直接输入 yes 就可以了,然后提示成功:

Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.
Hi smartwen! You've successfully authenticated, but GitHub does not provide shell access.

git推送到GitHub步骤:

git init

git add file

git commit -m "注释"

git remote add origin git@github.com:smartwen/selIDE

git push -u origin master

 解决一个巨坑

我使用了命令:

git push -u origin master
结果报错如下:
error: failed to push some refs to 'git@github.com:你的远程库名.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
从提示可以看出,是由于两者不同步,因此需要先pull,进行合并然后在进行push,
因此先使用
git pull --rebase origin master
将远程文件同步下来。
然后再执行推送
git push -u origin master
终于,成功!
 

 

 

 

 

 

 


posted @ 2017-11-24 16:10  smartwen  阅读(4633)  评论(0编辑  收藏  举报