Skip to main content
  1. Posts/

Git Cheat Sheet

·2 mins·
Git Web Dev
Mathew Schlemmer
Author
Mathew Schlemmer
Table of Contents
Web - This article is part of a series.
Part 1: This Article

Overview
#

This is intended to be a Git quick bites reference. The commands found in this document are commonly used commands for code and repository management. For more detailed explanations and command options please reference Git Docs.

Git Commands
#

git add
#

  • git add <file_name> # stages file(s) or directory for next commit
  • git add -all # stages all changed file(s) and directory for next commit

git branch
#

  • git branch # view current branch
  • git branch <branch_name> # create new branch
  • git branch -d <branch_name> # delete branch of choice

git clone
#

  • git clone --recurse-submodules <repository> # important for cloning Hugo repository

git commit
#

  • git commit -m "Message about this commit"

git config
#

  • git config --global user.name "username" # configure your user
  • git config --global user.email "[email protected]" # configure your email
  • git config pull.rebase false # merge
  • git config pull.rebase true # rebase
  • git config pull.ff only # fast-forward only

git checkout
#

  • git checkout <branch_name> # change branches
  • git checkout -b develop remotes/origin/develop

git fetch
#

  • git fetch <remote> <branch_name>

git merge
#

  • git merge <branch_name> # merges branch into current working branch

git pull
#

  • git pull # pull any changes from remote repository
  • git pull <remote> <branch_name> # pull any changes from specific remote branch

git push
#

  • git push <remote> <branch_name> # pushes branch changes to remote repository
  • git push origin --delete <branch_name> # deletes remote branch

git stash
#

# could be considered advanced

  • git stash
  • git stash list
  • git stash pop
  • git stash apply
  • git stash apply stash@{n}
  • git stash drop stash@{n}
  • git stash clear

Other Commands
#

  • git diff # used to check the differences in a file
  • git init # initialize a new repository
  • git log # view the log of commits
  • git status # check the current status of your repository
  • git switch <branch_name> # switches to desired branch

Common Command Sequence
#

# when working with multiple branches

git fetch --all && git branch -a && git checkout -t origin/<branch_name>

Web - This article is part of a series.
Part 1: This Article