Git branch cheatsheet

Key: Enter your information in places highlighted in “Italics”.

Creating a new branch:

  • git branch “name
  • git branch “name” “version id

Switching branch:

  • git switch “branch name(this is the preferred method)
  • git checkout “branch name

Rename branch:

  • git branch -m “new name

Renaming a non-head branch:

  • git branch -m “old name” “new name

Tracking branch:

  • git checkout — track “branch name

Deleting branch:

  • git branch -d “branch name

Deleting a branch that has been pushed to a version control platform such as GitHub:

  • git push origin –delete “branch name

Merge branch:

  • git merge “branch name you want to merge to current head

Compare branch:

  • git log “branch name” “other branch name