merge branch git commands code example

Example 1: merging branches in git

//Make sure you are in your branch. Develop is a a branch in this case

git checkout master
Switched to branch 'master'

git pull
To pull changes of team members to your master

git checkout develop
git merge master
Resolve Conflicts in develop

git checkout master
git merge develop
To merge your final changes along with other changes to your master

git pull
If there were any additional changes made meanwhile

git push
To push the final master to the master repository

git checkout develop
//Move to branch again to work

Example 2: git merge two branches

git checkout targetBranch
git merge sourceBranch

Example 3: git merge branche

/*
-> we have two branches 'dev' and 'master'
-> we want marge or sync branch 'dev' to branch 'master'
*/
// select all changes
$ git add .
// commit changes
$ git commit –m "fix bug ..."
// switch to master
$ git checkout master
Switched to branch 'master'
// start merge 
$ git merge dev