42

I've cloned repository A's master branch from git and created my own branch called Li. I've made some changes a while ago and pushed the contents of local Li to remote Li.

Now I've pulled some updates from remote master to my local master branch and from the local master branch to the local Li, and I'm trying to push the updates from local Li to remote Li. However, when I try to run:

git checkout Li git push origin Li 

I get the following error:

error: failed to push some refs to '[email protected]:anodejs/system.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

Note that my local master branch is updated (I invoked git pull origin master) and merged into the local Li branch. I did, however, add local Li a new file, so local Li is not identical to local master (but this shouldn't matter, right?)

Thanks, Li

2
  • Did you commit changes on Li branch before trying to push it? Commented Apr 22, 2013 at 17:28
  • 1
    Came to this question with the same problem and the answers here didn't help. Turned out my problem was I wasn't in a branch - see stackoverflow.com/a/18601467/5002633 for how I diagnosed / fixed it. Commented Jul 19, 2016 at 15:13

4 Answers 4

36

Updates were rejected because a pushed branch tip is behind its remote.

git config --global push.default current 

Try the command above to set the current branch as default and

git push 
Sign up to request clarification or add additional context in comments.

1 Comment

Note this command changes the fundamental behavior of git push, which is often, but not always, intended. Users who want to know what those behaviors are can see this question or this question.
30

Find the diff with git fetch && git log Li..origin/Li. I would guess you've rebased or otherwise recut Li since last time you pushed, but that command should tell you exactly what's in the remote that isn't in the local. You can find what's in either (but not both) with the triple-dot syntax: git log Li...origin/Li.

If the diff is expected, then just merge with git merge origin/Li and then git push. If the change is unwanted, overwrite the remote with git push -f origin Li. Only do this if you want to abandon the remote's changes.

3 Comments

When I invoke the fetch&&log command I can see that there is a merge pull request from origin/master. But when I try "git merge origin/Li" I see that there's nothing to merge (already up-to-date!). I believe that push -f will work, but I think that if I'll figure it out it will help me understand git
gave up, went for push -f which solved the issue as you said. Thanks
Big thanks. I read a few advices on the StackOverflow, but nothing worked for me but this. You made me happy, because I haven't lost my good humour just by problem with git :) It is a little bit frustrating when you are testing solution by solution and still get the same error message ;D Very best
0

You can force push changes to remote address, but it can produce new remote branch

git push subtree_remote_address.git `git subtree split --prefix=subtree_folder`:refs/heads/branch --force 

Comments

0

git branch --set-upstream-to=origin/ master

If you are having the error when you are on 'master' branch, try the following command:

git branch --set-upstream-to=origin/master

Or, a shortcut: git push -u origin master

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.