4

I checked out a new branch from our repo. Everything is working fine for our develop branch. But on the new branch 'push' isn't doing anything.

Everything looks normal - there are 2 commits to push.

-> git branch -vv
  develop   8ab7ef1 [origin/develop] Merge branch 'develop' of git.example.com:core-platform into develop
* hotfix112 8521cef [origin/hotfix/1.1.2: ahead 2] CORE-1263 - Completed merging from dev into hot fix.

But Push doesn't do anything:

-> git push
Everything up-to-date

-> git status
# On branch hotfix112
# Your branch is ahead of 'origin/hotfix/1.1.2' by 2 commits.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean

I found that 'git pull' uses remote, but 'git push' doesn't:

-> git remote show origin
* remote origin
  Fetch URL: git@git.example.com:core-platform.git
  Push  URL: git@git.example.com:core-platform.git
  HEAD branch: develop
  Remote branches:
    core-platform-1.0.0 tracked
    develop             tracked
    hotfix/1.1.2        tracked
    master              tracked
    release/1.0.0       tracked
    release/1.1.1       tracked
  Local branches configured for 'git pull':
    develop   merges with remote develop
    hotfix112 merges with remote hotfix/1.1.2
  Local ref configured for 'git push':
    develop pushes to develop (up to date)
->

I cannot figure out why hotfix112 is not linked to the remote, but the pull is.

How do I fix this configuration?

Taylan Aydinli
  • 4,333
  • 15
  • 39
  • 33
Steve s.
  • 301
  • 1
  • 4
  • 13
  • Check this out http://stackoverflow.com/questions/3882583/git-is-telling-me-your-branch-is-ahead-of-origin-master-by-2-commits-and-i – rozar Aug 13 '13 at 17:15

3 Answers3

2

Git acts as you've described because you have the following situation:

  • you have a local branch (hotfix112) which is tracking a differently-named remote branch
  • you have push.default option set to matching (which is default) or simple

As usually the case with git, you have a few alternatives how to set up git to act as desired:

1.) The easiest would be to change the name of your local branch to match the name of the remote branch. Afterwards, push starts working automatically. So just rename branch 'hotfix112' to 'hotfix/1.1.2':

git branch -m hotfix112 hotfix/1.1.2

2.) You can change the push behaviour via setting option push.default to 'tracking'. Because you already have branch 'hotfix112' set to track origin/hotfix/1.1.2, git push will work as desired. To set the local git option run:

git config --local push.default tracking

3.) You can manually edit your .git/config file and set push to match local refspec 'hotfix112' to remote 'hotfix/1.1.2'. You should add the push line below your [remote "origin"] section:

[remote "origin"]                                                               
  url = ...
  fetch = ...
  push = hotfix112:hotfix/1.1.2

First and third approach work only on the hotfix112 branch. The second works for all tracking branches in that repository (or globally if global option was used).

jurglic
  • 3,599
  • 1
  • 17
  • 13
  • 1
    simple will be the value of push.default in 2.0 but matching is currently the default (http://git-scm.com/docs/git-config). – Eric Mathison Aug 13 '13 at 18:47
  • You're correct Eric, I forgot I set it in my global config a while ago... have updated accordingly... Cheers! – jurglic Aug 13 '13 at 20:23
  • thx, I chose #1. A shorter branch name seemed like a good idea, but causes confusion downstream. – Steve s. Aug 13 '13 at 23:30
  • but why does Git say `Everything up-to-date` and not something like "local branch name does not match remote branch name and push.default is set to X" ? – doubleOrt Jun 19 '17 at 14:55
0

Try git push origin/hotfix/1.1.2 (the remote branch) hotfix112 (the local branch), possibly afer doing a push to the remote it will create a link. Weird though that is did not when you branched.

Jack Thor
  • 1,554
  • 4
  • 24
  • 53
  • Thanks for the hint. This worked fine: `git push origin hotfix112:hotfix/1.1.2`. But alas the config didn't change. – Steve s. Aug 13 '13 at 17:32
  • Hmm how about this http://stackoverflow.com/questions/8170558/git-push-set-target-for-branch – Jack Thor Aug 13 '13 at 17:37
  • 1
    Bingo: `git push -u origin hotfix112:hotfix/1.1.2` `Branch hotfix112 set up to track remote branch hotfix/1.1.2 from origin.` – Steve s. Aug 13 '13 at 18:10
0

The current behavior of git push (without any additional parameters) is to push all branches having the same name in the local and remote repository. Since your local branch name differs from your remote branch name, if you change them to match, git push should push your changes. Be advised though that this behavior will be changing in a future version of git (probably 2.0). See: http://article.gmane.org/gmane.comp.version-control.git/193308. If you would like to change the behavior of git push right now, type git help config and search for "push.default".

Eric Mathison
  • 1,210
  • 10
  • 16