开发者

Git - How to track a remote branch that you created from a local branch?

Here's the scenario.

I have a series of commits in branch my_new_branch

I want to push this branch up to the remote repo as a different name and track it.

If I do:

git push origin my_new_branch:different_name

it pushes the branch up fine.

But if I stay in my_new_branch and make another commit, if I just do

git push

it says 'Everything up to date'

Further, if I look at .git/config, I can see it hasn't set up a tracking branch.

Of course I can just do

git push origin my_new_branch:different_name 

a开发者_如何学编程gain, but how do I get it to track?

If I do

git checkout -b my_new_branch origin/different_name

it complains that the branch name already exists.

Thanks!


As you mention, the question "How do you make an existing git branch track a remote branch?" indicate the possibility to set the upstream branch (the one to where you push) for a local branch (since Git1.7.0).

git branch --set-upstream my_new_branch origin/different_name

which replaces:

git config branch.my_new_branch.remote origin
git config branch.my_new_branch.merge refs/heads/different_name

By default, git push uses a special refspec ':'

The special refspec : (or +: to allow non-fast-forward updates) directs git to push "matching" branches:
for every branch that exists on the local side, the remote side is updated if a branch of the same name already exists on the remote side.
This is the default operation mode if no explicit refspec is found (that is neither on the command line nor in any Push line of the corresponding remotes file).

Hence your troubles with "git push" (no arguments).


If you remember to use -u when you push, git will set this up for you automatically.

-u, --set-upstream

For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands. For more information, see branch..merge in git-config(1).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜