如何在git中配置本地分支以永久跟踪另一个命名的远程分支

如何在git中配置本地分支以永久跟踪另一个命名的远程分支

问题描述:

这似乎是一个非常基本的操作,但是我还没有找到最终的答案.

This seems like a really basic operation, but I haven't been able to find a conclusive answer to it.

我经常在本地创建一个新的分支,如下所示: git checkout -b new_feature

I often locally create a new branch like this: git checkout -b new_feature

然后,我通过bitbucket或gitlab创建一个远程分支,并希望将我的本地分支链接到该新创建的远程.

Then later, I create a remote branch through something like bitbucket or gitlab and want to link my local branch to that newly created remote.

我知道我可以通过以下方式推送到该遥控器:

I know i can push to that remote via:

git push origin new_feature:bitbucket_branch_name

但是我发现这很乏味,并且想知道是否有更优雅的解决方案,例如.将远程分支设置为跟踪一次,然后从此开始使用经典git pull/git push.

But I find this tedious and wonder if there's a more elegant solution to this, eg. set the remote branch to track once and work with classic git pull/git push from then onward.

您要查找的命令是:

git branch --set-upstream-to=origin/bitbucket_branch_name new_feature

详细了解 git branch --set-upstream-to .