Skip to content

Instantly share code, notes, and snippets.

@rocarvaj
Last active December 9, 2017 18:53
Show Gist options
  • Select an option

  • Save rocarvaj/8498045 to your computer and use it in GitHub Desktop.

Select an option

Save rocarvaj/8498045 to your computer and use it in GitHub Desktop.
Git branching

Git cheat sheet: Stuff I always forget

See: http://documentup.com/skwp/git-workflows-book#

  1. Create branch

  2. Commit a temp "bookmark":

git commit -a -m "uncommit me: need to finish stuff in the user model"

  1. Then uncommit:

git reset --soft HEAD^

  1. Push to remote:

git push origin <branch-name>

  1. If I'm working from another machine:

git checkout -t -b <branch-name> origin/<branch-name>

  1. Merge branch into master:

git checkout master

git merge <branch-name>

  1. Delete local branch:

git branch -D <branch-name>

  1. Delete remote branch:

git push origin :<branch-name> or git push origin --delete <branch-name>

  1. Change remote branch that a branch is tracking

Without deleting anything, using git up to v1.7.12:

git branch --set-upstream branch_name your_new_remote/branch_name

Using git v1.8.0 or later:

git branch branch_name --set-upstream-to your_new_remote/branch_name

Create branch

git checkout -b <branch-name>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment