Home > Software engineering >  Git push to a repository which is 1 commit ahead
Git push to a repository which is 1 commit ahead

Time:04-08

I am working on a repository, where lets say I have created a commit 'B'. Commit 'A' is the origin/master. It looks like this:

A -------------------- B
(origin/master)      (HEAD)

But someone else pushed a commit (consider it as 'Z') before me, and without knowing that I created another commit on top of B, consider it as 'C'. It looks like this now.

      (origin/master)
A --------- Z
 \
  \
   -------- B -------- C
                      (HEAD)

How can I first pull the commit 'Z' and then push my local commits. I can confirm (Z) and (B, C) are unrelated file changes. I want them to eventually look like this:

A -------- Z -------- B -------- C
                          (HEAD, origin/master)

I have tried git pull --rebase but no use. Let me know how can I re-enable it

CodePudding user response:

Actually, git pull --rebase should be working here to arrive at the A -- Z -- B -- C branch you want. You could also try an explicit rebase operation followed by a push:

# from local master
git fetch origin
git rebase origin/master
git push origin master
  • Related