创建时关联远程分支
命令:git branch --track <新分支名> <远程分支名>
例:git branch --track dev origin/dev
已有分支关联远程分支
命令:git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
官方解释
-u <upstream>
--set-upstream-to=<upstream>
Set up <branchname>'s tracking information so <upstream> is considered <branchname>'s upstream branch. If no <branchname> is specified, then it defaults to the current branch.
例:
git branch -u origin/dev
或
git branch -u origin/dev dev
推送到远程仓库时关联
命令:git push [--set-upstream] [远端名称 [本地分支名][:远端分支名] ]
git push origin master:master
1)如果远程分支名和本地分支名称相同,则可以只写本地分支
git push origin master
2)–set-upstream 推送到远端的同时并且建立起和远端分支的关联关系
git push --set-upstream origin master:master
3)如果当前分支已经和远端分支关联,则可以省略分支名和远端名
git push
其它操作
查看: git branch -vv
解除关联:git branch --unset-upstream [<分支名>]
(不写分支名,默认当前分支)
删除远程分支:git push origin --delete <分支名>
附:官方文档
https://git-scm.com/docs/git-branch/zh_HANS-CN