Wednesday, June 10, 2015

How to rebase your pull request

But, why ?

Your pull request(PR) might be pretty old and in mean time many people would have changed the same code. So you can't simply merge your PR into master branch because of the conflicts.

Step 1:
Fetch the latest code from remote master branch.
> git fetch upstream

here upstream is pointing to a remote repository.

Step 2:
If you have multiple commits, it's better to squash them. But it's an optional step.
>git merge-base <yourforkedbranch> <mainremotebranch>
Example: git merge-base TISTUD-9000 release

This will give the hash-id.
>git rebase --interactive <hash-id>

It will list down the commits, If you have more than one, you can replace 'pick' by 'squash' for commits expect first one.
Example:
pick 4455 
squash 5555
squash 85858

Step 3:
Run rebase command
>git rebase upstream/master

For sure, this will fail because of the conflicts. I mean, that's the main reason why we wanted to go for rebase here.

And once you resolve the conflicts continue with the rebase --continue.

Step 4: 
Update the pull request forcefully
>git push -f

or
> git push origin <yourbranch> -f

This is the crystal clear resource which will talk about this.


No comments:

Post a Comment