git branch // list all branch in local
git branch -a // all branches remote + local
git branch my-branch // create new branch
git checkout my-branch // get into created branch
git branch -d my-branch // delete branch
git branch -m my-branch new-branch // rename branch
// merging
git checkout master
git merge my-branch
Merge
Fast Forward
git branch -n branch1
// make some changes & commit than
git checkout master
git difftool master branch1 ( just to verify changes )
git merge branch1 ( safe merge without conflict, as no modification in master branch )
git branch -d branch1
// now their is no history available for branch1
// merge with fast forward disabled ( in case you want to keep history )
git merge branch1 --no-ff
// git merge with commit message ( specially when their is chane in master after branch creation)
git merge my-branch -m "Commit Message"
Handle Merge Conflict
Master Branch> git merge my-branch
If have conflict git will create a backup file for you <file>.orig
to avoid generation of such temp file use...
git config --global mergetool.keepBackup false
<<<<<<<<<<< HEAD
anything here is the branch you are in (master)
===================
anythinh here is from branch you trying to merge (my-branch)
>>>>>>>>>>>>>> my-branch
Merge toll to resolve conflict
git mergetool ( open up p4merge tool )
// select color buutton to select changes & quit
git commit -m "I am done"