Git本地分支与远程分支关联

当clone完版本库,切换到开发分支后,使用git pull -r 拉取并合并分支之后会出现一下提示:

$ git pull -r
From ssh://192.168.1.226:29418/ethank-server
bc86d14..b72fc88 dev -> origin/dev
There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
See git-pull(1) for details

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=origin/<branch> dev

这是由于本地分支并没有和远程分支进行关联,关联之后会在.git/config中增加 一下类似的条目:

[branch "master"]
remote = origin
merge = refs/heads/master

我们根据提示执行命令:git branch --set-upstream-to=origin/dev dev

执行后.git/config文件中会增加:

[branch "dev"]
remote = origin
merge = refs/heads/dev

之后就可以使用git pull -r

但如果手动先git fetch 然后再git rebase origin/dev 手动合并就不会弹出错误提示 ,

建议还是使用git branch --set-upstream-to关联远程分支

原文地址:https://www.cnblogs.com/xingjunli/p/4923832.html