Thursday, October 18, 2012

GIT rebasing and pull request processing

Minor explanation with example

Checkout to master

$ git pull --rebase origin master

Create a new branch for each feature. Say we are implementing a new feature => feature1, create a branch

$ git checkout -b feature1 

Now we have a copy of master in feature1 branch. Now you can work on this branch. It will be better to commit all changes at last before pushing the branch. If we have created this branch long time ago, by the time the master would have got updated from other developers. So, checkout to master and run $ git pull --rebase origin master and then checkout to feature1.

Now,
$ git rebase master
If merge conflict occurs in our rebase then resolve the conflict and stage the files, please dont commit them and run $ git rebase --continue or abort the rebase by $ git rebase --abort.

Commit and push the new branch

$ git push origin feature1

When its done, after accessing the branch through browser initiate the pull request. On initiating pull request we can set the base merge branch. The pull request can be accepted and merged if a link below called Merge is shown in green (ready to go).

If we need to merge multiple commits to one 

Now use git log, which lists the commits. If we want to merge the last 2 commits then use

$ git rebase -i HEAD~2 

Update the commits to be squashed and picked. On squashing the commit will be merged to a the picked one then, save the commit and push the branch using 

$ git push -f origin feature1