a blog for those who code

Friday 30 September 2016

How to Merge Branches with Specific commits in Git

In this post we will be discussing about merge branches with specific commits in Git. Lets say you want to merge a pull request from one branch to another branch with only specific commit and not all commits then you cannot use native GitHub Pull Request feature. As because native GitHub pull request will allow you to merge all the commits and not the specific commits. We will be taking advantage of git cherry-pick for doing specific commit pull request.

What is Git Cherry-Pick

Cherry picking in git means to choose a commit from one branch and apply it onto another. It is different than merge because cherry-pick will only allow one commit at a time whereas merge applies many commits onto another branch. An example can be when moving changes from development environment to production environment you only want a certain commit to move rather than whole branch so you will just cherry-pick the commit onto another branch.

How to Use Git Cherry-Pick

Get the hash of the particular commit and type git cherry-pick commit_hash_value

Steps to Merge Single Commit from Development To Master Branch

Step 1 : Pull down development branch locally using git command : git pull development
Step 2 : Checkout master branch (the branch you are merging) : git checkout master
Step 3 : Cherry Pick the commit you want into master branch : git cherry-pick commit_hash_value
Step 4 : Push the changes to master : git push origin master

Available Options when using Git Cherry-Pick are :

Please Like and Share the CodingDefined Blog, if you find it interesting and helpful.

No comments:

Post a Comment