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

Here is the script.

I have a series of commits in the my_new_branch branch

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

If I do this:

git push origin my_new_branch:different_name 

he perfectly repels the branch.

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

 git push 

he says "Everything is relevant"

Also, if I look at .git / config, I see that it has not configured the tracking branch.

Of course I can just do

 git push origin my_new_branch:different_name 

but how do I track it?

If i do

 git checkout -b my_new_branch origin/different_name 

he complains that the branch name already exists.

Thanks!

+4
source share
2 answers

As you mentioned, the question “ How to make an existing git tracking branch a remote branch? ” Indicates the possibility of installing the branch upstream (the one where you click) for the local branch (with 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 the special refspec ' : '

Special refspec : (or +: to allow immediate updates) directs git to click on the "appropriate" branches :
for each branch that exists on the local side, the remote side is updated if a branch with the same name already exists on the remote side.
This is the default operation mode if no explicit refspec is found (this is not on the command line or on any Push line of the corresponding file of deleted files).

Therefore, your problems with git push (no arguments).

+2
source

If you forget to use -u on click, git will automatically install this for you.

-u, --set-upstream

For each branch that has been updated or successfully pushed, add a link up (tracking), used without git-pull (1) and other commands. See the section ...merge in git -config (1) for more information.

+1
source

All Articles