Munchkin
Munchkin

Reputation: 4946

git push rejected, maybe because of rebase

I have an automated Jenkins job which simply does the following:

remoteA is the remote where developers actually push their code.

remoteB is never touched manually, it only receives udates trough that automated Job.

It worked well for a while, but now I get Updates were rejected because the tip of your current branch is behind its remote counterpart. when trying to push into remoteB

As far as I know, this happens when

Upvotes: 1

Views: 108

Answers (1)

CodeWizard
CodeWizard

Reputation: 142094

If you did a rebase which modified the history so you cannot push to the remote unless you wish to overwrite and change the content of your repository.

If you still wish to push the content you must use the -f

# FORCE overwrite of old content with the new result of you rebase 
git push -f  

In your case that the content is handled by Jenkins, a rebase can be a good reason to why it stopped working.


How to find out if there was a rebase

Check the diff between the 2 branches (local vs remote)

# fetch all remotes if you have multiple ones
git fetch --all

# check the diff between the 2 branches (2 ..)
git diff localBranch..origin/remoteBranch


# check the diff between the 2 branches (3 ..)
git diff localBranch...origin/remoteBranch 

you can read more about git diff
How to show uncommitted changes in Git

Upvotes: 1

Related Questions