Pretty often we are in situation where we need to merge branches especially while using "branch per feature" pattern to push our changes to repo.

You may follow these simple yet very important steps to merge your branches.

  1. Assuming that you are on "master" branch on your local repo, do this to check the branch.

git branch

Expected output

master

  1. Checkout the branch you want to merge, example you want to merge branch "feature-devise", So do this

git checkout feature-devise

Expected output

master

feature-devise

  1. Come back on master branch to start merge process

git checkout master

Expected output

master

feature-devise

  1. Now merge the branch "feature-devise" with "master" so do this

git merge feature-devise

Expected output

Either merge conflicts or success

  1. You might face merge conflicts and git is intelligent to help you resolve conflicts. This is a very important step so carefully resolve merge conflicts for all the files that are shown as "conflicts" as a result of step-4 above. You may do this to check status of conflicted files and git will show you unresolved lits of conflicted files.

git status

  1. Once you merge, i.e. diff and merge files that you want to resolve, perform following step to add them back to merge

git add file_name

Now do,

git status

and this will result into one file less in your overall list of "unresolved merge conflicted files"

  1. Keep on repeating step-6 above for all the files you want to resolve merges for.

  2. Now finally do this again

git status

and if this results into git showing you 0 conflicts, then move to next step else resolve conflicts

  1. Merge again to check if any unmerged files still left

git merge feature-devise

  1. You are all set now to finalize your merge, do this to commit all your merged files

git commit

  1. Finally push your merge to master branch

git push origin master

  1. You are done with merging branch "feature-devise" with "master". At this point you may refer "Github.com" to confirm your merge. Under list of commits in Github.com, it should display merge commit as "Merge branch feature-devise".