How to configure a local branch to permanently track a differently named remote branch in git

岁酱吖の 提交于 2019-12-11 15:48:27

问题


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

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

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

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.


回答1:


The command you are looking for is:

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

Read more about git branch --set-upstream-to.




回答2:


You can set the remote origin by

git remote set-url origin bitbucket_url

verify by

git remote -v

Next set branch by

git branch -u bitbucket_branch_name/local_branch_name

From then on git pull/push works with that as default, i.e. no url needed.



来源:https://stackoverflow.com/questions/51079736/how-to-configure-a-local-branch-to-permanently-track-a-differently-named-remote

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!