Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git track branch with different name

Tags:

git

git-branch

I have a repo which tracks non-default branches. So, there is a local branch named "master" which should track "origin/master-13.07". I've done "push -u", and I believe it should be enough, the branch is tracked. Output of the git branch -vv:

C:\work\repo>git branch -vv
  stuff     68792df [origin/stuff-13.07] Small bugfix
* master 68792df [origin/master-13.07: ahead 1] Small bugfix

Output of the git status

C:\work\repo>git status
# On branch master
# Your branch is ahead of 'origin/master-13.07' by 1 commit.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean

All seems all right, but when I just use "git push" (as git recommends me above), it fails:

C:\work\repo>git push
fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use

    git push origin HEAD:master-13.07

To push to the branch of the same name on the remote, use

    git push origin master

Yes, I know that the name doesn't match, this is exactly what I want and I told so to git by "push -u". Why I cannot just use "push"?

C:\work\repo>git --version
git version 1.8.3.msysgit.0

C:\work\repo>git config push.default
simple
like image 885
kan Avatar asked Jun 11 '13 10:06

kan


People also ask

How do I pull a remote branch to a local branch with a different name?

To be precise, renaming a remote branch is not direct – you have to delete the old remote branch name and then push a new branch name to the repo. Step 2: Reset the upstream branch to the name of your new local branch by running git push origin -u new-branch-name .

How do I checkout someone else's branch?

If you want to check out a remote branch someone published, you first have to use git fetch . This command downloads the references from your remote repository to your local machine, including the reference to the remote branch. Now all you need to do is use git checkout <remote branch name> .

How do I track a local branch remotely?

When you're publishing a local branch. You can tell Git to track the newly created remote branch simply by using the -u flag with "git push".


1 Answers

Ok. With the informations you added, I think you simply have to change push.default to value upstream.

You probably configured the actual value after upgrading Git and seeing this message :

warning: push.default is unset; its implicit value is changing in 
Git 2.0 from 'matching' to 'simple'. To squelch this message 
and maintain the current behavior after the default changes, use: 

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use: 

  git config --global push.default simple

According to the documentation, value simple must reject a push when branch names are different. See Git Config (search for push.default).

like image 152
Guillaume Darmont Avatar answered Sep 20 '22 14:09

Guillaume Darmont