跟蹤遠(yuǎn)程分支
如果用git push指令時(shí),當(dāng)前分支沒有跟蹤遠(yuǎn)程分支(沒有和遠(yuǎn)程分支建立聯(lián)系),那么就會(huì)git就會(huì)報(bào)錯(cuò)
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
因?yàn)楫?dāng)前分支沒有追蹤遠(yuǎn)程指定的分支的話,當(dāng)前分支指定的版本快照不知道要作為服務(wù)器哪一個(gè)分支的版本快照的子節(jié)點(diǎn)。簡單來說就是:不知道要推送給哪一個(gè)分支。
那么如何建立遠(yuǎn)程分支:
- 克隆時(shí)自動(dòng)將創(chuàng)建好的
master分支追蹤origin/master分支
git clone 服務(wù)器地址
git checkout -b develop origin/develop
在遠(yuǎn)程分支的基礎(chǔ)上建立develop分支,并且讓develop分支追蹤origin/develop遠(yuǎn)程分支。
git branch --set-upstream branch-name origin/branch-name
將branch-name分支追蹤遠(yuǎn)程分支origin/branch-name
git branch -u origin/serverfix
設(shè)置當(dāng)前分支跟蹤遠(yuǎn)程分支origin/serverfix
查看本地分支和遠(yuǎn)程分支的跟蹤關(guān)系
git branch -vv
比如輸入
$ git branch -vv
develop 08775f9 [origin/develop] develop
feature_1 b41865d [origin/feature_1] feature_1
* master 1399706 [my_github/master] init commit
develop分支跟蹤origin/develop
feature_1分支跟蹤origin/feature_1
master跟蹤了my_github/master,且當(dāng)前分支為master分支
那么假如我此時(shí)想要將master的改變推送到origin服務(wù)器的master分支上:
$ git checkout master//切換到master分支
...
$ git branch -u origin/master//將當(dāng)前分支跟蹤origin/master
Branch 'master' set up to track remote branch 'master' from 'origin'.
之后就可以執(zhí)行g(shù)it add和git commit了
現(xiàn)在再查看一下本地和遠(yuǎn)程的分支關(guān)系:
$ git branch -vv
develop 08775f9 [origin/develop] develop
feature_1 b41865d [origin/feature_1] feature_1
* master 1399706 [origin/master] init commit
master已經(jīng)跟蹤了origin/master了