Git Merge two branches

How to merge two git branches branch1 to branch2

Check out both branches as follows, first check out branch1

git checkout branch1

Check out branch 2

git checkout branch2

To merge branch1 and branch2ce you check out both branches, switch to the branch which you want to merge and then execute below command with branch name from which you want to merge from

git merge branch1

If there are any merge conflicts it’ll show the list of files, go through each and merge conflicting lines by cherry picking their changes and add yours on top of it.

If there are no conflicts, commit changes and push to remote branch2

git commit -m "merged latest changes from branch1"
git push

Now your branch2 contains all the changes from branch1

Leave a Reply

Your email address will not be published. Required fields are marked *

Enable Notifications OK No thanks