2

I have a branch that was created from develop (created from Atlassian Stash) that has a handful of commits. When I try and push my commits I get an error about updates being rejected because a pushed branch tip is behind its remote counterpart. Based on my understanding, this means that someone else committed, so I should pull the changes. However, there is nothing to pull. Funny thing is looking at Atlassian Stash I'm able to see that my push has in fact gone through.

$ git push
To REPO_URL
 ! [rejected]        develop -> develop (non-fast-forward)
 ! [rejected]        feature/135-add-button-to-ticket-indicating -> feature/ 135-add-button-to-ticket-indicating (non-fast-forward)
error: failed to push some refs to 'REPO_URL'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I'm not sure what it is I'm doing wrong, but I would love to know why this particular issue rears its ugly head every few days. In the past I have I have simply forced the push, but that doesn't help me understand why the issue is happening in the first place.

How can I diagnose why this issue is happening?

onetwothree
  • 672
  • 1
  • 10
  • 20
  • 1
    What does `git log --graph --oneline --decorate` show you for your remote branch and your local branch? – Makoto Apr 01 '15 at 14:57
  • I can't seem to find anywhere how exactly the log message is laid out, but I believe my remote branch is `origin/152-send-emails-rather-than-faxes` (red letters) and the local branch is `152-send-emails-rather-than-faxes` (green letters). – onetwothree Apr 01 '15 at 15:58
  • If your local is behind, the tip of your local will graphically appear after the tip of your remote. You've also fetched the most recent code, correct? That way the view is entirely accurate. – Makoto Apr 01 '15 at 15:59
  • Now this has got me confused because my current branch is `152-send-emails-rather-than-faxes`, but as shown in my question, it appears to be attempting a push to `135-add-button-to-ticket-indicating`. – onetwothree Apr 01 '15 at 16:01

1 Answers1

2

It looks like, on a closer inspection, that Git is pushing more branches than you are aware of.

If you're only working on one branch, and when you type git push you only want that branch to be pushed, then you need to adjust your global configurations to the following:

git config --global push.default current

This will only push the branch that you are currently on to the remote repository.

Makoto
  • 104,088
  • 27
  • 192
  • 230