接到新的需求,我新建了一個分支用來開發(fā)新需求羡藐。之前的分支都是自己直接用命令行新建的贩毕,沒出過什么亂子,這次偷懶用工具直接新建的分支仆嗦,誰知道提交代碼時候就提交交不上了辉阶。報錯提示如上。
如果用git push指令時,當(dāng)前分支沒有跟蹤遠(yuǎn)程分支(沒有和遠(yuǎn)程分支建立聯(lián)系)谆甜,那么git就會報錯
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
因為當(dāng)前分支沒有追蹤遠(yuǎn)程指定的分支的話垃僚,當(dāng)前分支指定的版本快照不知道要作為服務(wù)器哪一個分支的版本快照的子節(jié)點(diǎn)。簡單來說就是:不知道要推送給哪一個分支规辱。
首先查看本地分支和遠(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分支
假如我此時想要將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了
如何建立遠(yuǎn)程分支:
1.克隆時自動將創(chuàng)建好的master分支追蹤origin/master分支
1. git clone 服務(wù)器地址
- 在遠(yuǎn)程分支的基礎(chǔ)上建立develop分支,并且讓develop分支追蹤origin/develop遠(yuǎn)程分支按摘。
2. git checkout -b develop origin/develop
- 將branch-name分支追蹤遠(yuǎn)程分支origin/branch-name
3. git branch --set-upstream branch-name origin/branch-name
- 設(shè)置當(dāng)前分支跟蹤遠(yuǎn)程分支origin/serverfix
4. git branch -u origin/serverfix