Linux(Centos 7)下安裝Git並配置連接GitHub


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目錄)和指定口令,保持默認,連續三次回車即可

復制SSH Key到GITHUB

打開該文件,id_rsa.pub文件內的內容,粘帖到github帳號管理的添加SSH key界面中

cat ~/.ssh/id_rsa.pub

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

測試是否連接成功

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

終於,成功!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM