git远程追踪分支的建立方法

本地分支不存在,创建追踪分支

git branch <localbranch> [--track] <remote>/<branch>

起点为远程分支时--track可省略。

本地分支不存在,创建追踪分支,同时切换到该分支

# 指定的branch名称不会出现在多个remote中导致歧义时
git switch <branch>
git checkout <branch>

# 使用远程分支名称作为本地分支名
git switch --track <remote>/<branch>
git checkout --track <remote>/<branch>

# 指定本地分支名称,起点为远程分支时--track可省略
git switch -c <localbranch> [--track] <remote>/<branch> 
git checkout -b <localbranch> [--track] <remote>/<branch> 

本地分支已存在,建立或更新上游追踪

git branch -u <remote>/<branch> [<localbranch>]

省略localbranch时使用当前branch。

本地分支已存在,在pull的同时建立或更新追踪关系

git pull --set-upstream <remote> <branch>

本地分支已存在,在push的同时建立或更新追踪关系

git push -u <remote> <localbranch>:<remotebranch>

git push -u <remote> <branch>    #本地branch名称与远程相同

参考资料

https://segmentfault.com/a/1190000002783245