Git Branching Quick Reference
Create a new branch and checkout
$ git checkout -b foobar
Makes some changes
$ touch foobar.txt
Stage the changes
$ git add foobar.txt
Commit changes to local repo
$ git commit -m "Adding foobar"
Create remote branch and set upstream
$ git push -u origin foobar
Merge into master
$ git checkout master
$ git merge foobar
Push to remote master
$ git push origin master
Delete local branch
$ git branch -d foobar
Delete remote branch
$ git push origin --delete foobar
Tips
View commits on your branch only (useful after merging master)
git log --first-parent
View all branches at any point in case you're curious
$ git branch -a
* foobar
master
remotes/origin/foobar
remotes/origin/master
Resolving merge conflict for specific files with "theirs" or "ours"
If a file can't be auto merged, and you know what version you want to use, simply checkout using either --theirs
or --ours
flag.
$ git merge origin/master
$ git checkout --theirs PATH_TO_FILE(S)
To do this for all the conflicted files, you can combine with a grep:
$ grep -lr '<<<<<<<' . | xargs git checkout --theirs
View this article for more thorough guidelines on git branching workflow: Understanding the Git Workflow
Written by Jason Seney
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#