在使用git创建本地分支时,可以在创建分支时就设置好跟踪的上游分支:
git checkout -b local_branch -t upstream_name/remote_branch
$ git checkout --help
-t, --track
When creating a new branch, set up "upstream" configuration. See "--track" in git-branch(1) for details.
If no -b option is given, the name of the new branch will be derived from the remote-tracking branch, by looking at the local part of the refspec
configured for the corresponding remote, and then stripping the initial part up to the "*". This would tell us to use "hack" as the local branch when
branching off of "origin/hack" (or "remotes/origin/hack", or even "refs/remotes/origin/hack"). If the given name has no slash, or the above guessing
results in an empty name, the guessing is aborted. You can explicitly give a name with -b in such a case.
如果在本地分支时忘了关联上游分支,可以在创建好上游分支后使用命令:
git branch --set-upstream-to=upstream_name/remote_branch
$ git branch --help
-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.