0

I am new to git, I have a use case, where I have raised the new commit and send it to code review, but then I realise my local mainline branch is not to the latest commit, someOne in my team had push the new commit to the remote mainline branch.

Let see the scanriao:

A--> B--> C <-- my local latest commit at C.

But My team raise the new commit and merged it to remote branch.Let say it is commit D.

So What I wanted to acheive is given below:

A-->B-->D--->C

HoW I can acheived above digram change. Like pull the latest changes from mainline(i.e D) and then push my changes(i.e C) as a latest commit over it.

Thanks.

JustDoIt
  • 39
  • 1
  • 7

3 Answers3

2

I always use (since Git 2.6, Q3 2015)

git config --global pull.rebase true
git config --global rebase.autoStash true

That way, a simple git pull is enough to get A-->B-->D--->C automagically.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

git fetch syncs the latest master.

After that in your branch run git rebase -i origin/master.

After rebasing push your branch to remote git push --force.

Now your branch aligns with master and your commit is the latest in the chain.

IMO it's OK to use git push --force in your branch (if you develop alone in there), but it's not OK to use it on master so be careful with that.

Tarmo
  • 3,851
  • 2
  • 24
  • 41
0
  1. Option

    stash your changes and take pull then apply you changes (and resolve conflicts if occur) and push code.

  2. Option

    git fetch syncs the latest master. After that in your branch run git rebase -i origin/master. After rebasing push your branch to remote git push --force. Now your branch aligns with master and your commit is the latest in the chain. by @tarmo