若是用git push
指令時,當前分支沒有跟蹤遠程分支(沒有和遠程分支創建聯繫),那麼就會git就會報錯javascript
There is no tracking information for the current branch. Please specify which branch you want to merge with.
由於當前分支沒有追蹤遠程指定的分支的話,當前分支指定的版本快照不知道要做爲服務器哪個分支的版本快照的子節點。簡單來講就是:不知道要推送給哪個分支。
那麼如何創建遠程分支:java
master
分支追蹤origin/master
分支git clone 服務器地址
git checkout -b develop origin/develop
git clone -b v1.0.0 git@gitlab (v1.0.0 是分支名)python
在遠程分支的基礎上創建develop
分支,而且讓develop
分支追蹤origin/develop
遠程分支。git
git branch --set-upstream branch-name origin/branch-name
將branch-name
分支追蹤遠程分支origin/branch-name
github
git branch -u origin/serverfix
設置當前分支跟蹤遠程分支origin/serverfixruby
git branch -vv
好比輸入bash
$ 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
,且當前分支爲master
分支服務器
那麼假如我此時想要將master的改變推送到origin服務器的master分支上:app
$ git checkout master//切換到master分支 ... $ git branch -u origin/master//將當前分支跟蹤origin/master Branch 'master' set up to track remote branch 'master' from 'origin'.
以後就能夠執行git add和git commit了
如今再查看一下本地和遠程的分支關係:gitlab
$ git branch -vv
develop 08775f9 [origin/develop] develop
feature_1 b41865d [origin/feature_1] feature_1
* master 1399706 [origin/master] init commit
master已經跟蹤了origin/master了
也能夠:
git clone XXXXXX
git checkout --track origin/org_dev
查看跟蹤關係:
fengdeMacBook-Pro:riki fengma$ git branch -vv
master b7a26015 [origin/master] 1
* org_dev 5c65d305 [origin/org_dev] modify user app name