kan
kan

Reputation: 28951

git track branch with different name

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

Upvotes: 18

Views: 6003

Answers (2)

VonC
VonC

Reputation: 1323203

With Git 2.20 (Q4 2018), the advice will slightly change.

See commit 8247166 (13 Nov 2018) by Ævar Arnfjörð Bjarmason (avar).
(Merged by Junio C Hamano -- gitster -- in commit 2c23f0b, 01 Dec 2018)

push: change needlessly ambiguous example in error

Change an example push added in b55e677 ("push: introduce new push.default mode "simple"", 2012-04-24, v1.7.11-rc0) to always mean the same thing whether the current setting happens to be "simple" or not.

This error is only emitted under "simple", but message is explaining to the user that they can get two sorts of different behaviors by these two invocations.

Let's use:

  • "git push <remote> HEAD" which always means push the current branch name to that remote,
  • instead of "git push <remote> <current-branch-name>" which will do that under "simple", but is not guaranteed to do under "upstream".

Upvotes: 0

Guillaume Darmont
Guillaume Darmont

Reputation: 5018

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).

Upvotes: 21

Related Questions