安裝git
sudo apt-get update
sudo apt-get install git
如果報(bào)錯(cuò) 缺少安裝包則執(zhí)行以下代碼后(代碼以報(bào)錯(cuò)后錯(cuò)誤提示中“correct this”之前的代碼提示為準(zhǔn))
sudo apt-get install -f
再次安裝。
首先到github官網(wǎng)申請一個(gè)賬號。
1.綁定用戶
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
2.配置SSH
ssh-keygen -t rsa -C "youremail@example.com"
之后一路按回車,配置成功后進(jìn)入.ssh目錄cd ~/.ssh,再執(zhí)行xdg-open?id_rsa.pub打開文件,得到ssh key公鑰
復(fù)制id_rsa.pub文件里面的全部內(nèi)容,打開github,點(diǎn)擊右上角的seetings,進(jìn)入SSH and GPG keys,點(diǎn)擊New SSH key,把剛才復(fù)制的內(nèi)容添加到key里面,在給你的密鑰起一個(gè)你能辨別的title。
再執(zhí)行以下代碼,確認(rèn)公鑰是否正確
ssh -T git@github.com
如果收到成功的確認(rèn)消息,就可以開始使用git了。
3.創(chuàng)建一個(gè)倉庫,選中Initialize this repository with a README選項(xiàng),因?yàn)檫@樣可以省略你之后添加README.md文件以下代碼。
git init
git add README.md
git commit -m "first commit"
git remote add originhttps://github.com/sususmile/-d.git
git push -u origin master
如果你是要在已存在并存在項(xiàng)目的遠(yuǎn)程倉庫里上傳文件則先執(zhí)行,如果是一個(gè)全新的項(xiàng)目則跳過這一步
git clone github? 地址
進(jìn)入你所要上傳的本地文件所在的目錄,并對其進(jìn)行初始化
git? ?init
git add .
輸入本次的提交說明,準(zhǔn)備提交暫存區(qū)中的更改的已跟蹤文件,單引號內(nèi)為說明內(nèi)容
git commit -m 'first_commit'
關(guān)聯(lián)遠(yuǎn)程倉庫,添加后,遠(yuǎn)程庫的名字就是origin
git remote add origin 地址
如果關(guān)聯(lián)出現(xiàn)錯(cuò)誤fatal: remote origin already exists,則執(zhí)行下列語句再進(jìn)行關(guān)聯(lián)
git remote rm origin
把本地庫的所有內(nèi)容推送到遠(yuǎn)程庫上
git push -u origin master
4.如果在推送時(shí)出現(xiàn)錯(cuò)誤error:failed to push som refs to.......,則執(zhí)行下列語句
git pull origin master? ?需要先獲取遠(yuǎn)端更新并與本地合并,再git push
或者
git fetch origin ? //獲取遠(yuǎn)程更新
git log -p master..origin/master //比較本地的master分支和origin/master分支的區(qū)別
git merge origin/master? ?//合并
5.如果再報(bào)錯(cuò)error: You have not concluded your merge (MERGE_HEAD exists).
則執(zhí)行
git merge --abort保留本地的更改,中止合并
git reset --merge重新合并
git pull重新拉取
git pull origin master
執(zhí)行4之后如果出現(xiàn)錯(cuò)誤是fatal: refusing to merge unrelated histories
則執(zhí)行以下代碼后再push
git pull origin master--allow-unrelated-histories