1

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

  • pull from remoteA
  • push into remoteB

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

  • (a) remoteB contains changes which remoteA doesn't contain -> I think that's not possible because no human and no other Jenkins Job touches remoteB
  • (b) someone did a rebase on remoteA. -> As I am no git professional, I am very unsure how to deal with that scenario. Hope someone here can help.
4
  • in this scenario try git pull --rebase remoteB remoteA and then try to run job again. NOTE: check the log and verify the commits before proceeding Commented Sep 26, 2019 at 10:26
  • 1
    It might be a good idea to see the changes in the branches remoteA and remoteB and to see what's different (do this with git fetch origin/remoteB && git diff remoteA..origin/remoteB. You can also check the remoteA history and check if it has strange changes to it. As to how to fix the problem, you cat either whip-out the bazooka and git push -f origin remoteB or do a git pull --rebase remoteB remoteA and then push to B Commented Sep 26, 2019 at 10:27
  • Just to explicitly confirm your assuption at the end, yes, (b) is the almost certain scenario here. Commented Sep 26, 2019 at 10:31
  • 1
    Yes, the only reason is that someone rewrote the history already pushed (with a rebase or an amend). And you can only solve your problem with a git push --force-with-lease (if you want to keep the 'new' git history). Commented Sep 26, 2019 at 11:39

1 Answer 1

1

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

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

1 Comment

--force did the trick. Now history of both remotes look identical (that was my goal). Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.