Skip to content

Instantly share code, notes, and snippets.

@MatthewKosloski
Last active April 19, 2018 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthewKosloski/2d1443b495c1cffd17a5badce8efb09e to your computer and use it in GitHub Desktop.
Save MatthewKosloski/2d1443b495c1cffd17a5badce8efb09e to your computer and use it in GitHub Desktop.
Git Branch Cheatsheet

Branches

Creating branches

Creates a new branch:

  git branch <branchname>

Create a new branch and switch to it with the following command. Any prior commits will be a part of the branch as well as the master.

  git checkout -b <branchname>

Viewing branches

Lists all your local branches, and also tells you which branch you're currently in:

  git branch

Type the following to view all remote branches:

  git branch -a

If you created a branch and it's not on the list, simply fetch for it. Fetch branches and/or tags (collectively, "refs") from one or more other repositories:

  git fetch

Change a branch

To change from one branch to another:

  git checkout <branchname>

Delete a branch

Delete remote branch:

  git push origin --delete <branchname>

Delete local branch:

  git branch -d <branchname>

Push changes

Push changes made from a branch to remote repository:

  git push origin <branchname>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment