如何在git中配置本地分支以永久跟踪另一个命名的远程分支 [英] How to configure a local branch to permanently track a differently named remote branch in git

查看:77
本文介绍了如何在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 .

这篇关于如何在git中配置本地分支以永久跟踪另一个命名的远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆