Git Cheat Sheet

Back to SIG Tooling & Set Up Tutorials

Author: Oliver Baldwin Edwards

Date: 2023-05-05

Below is a non-exhaustive list of everyday Git commands and their associated meanings.

Commands relating to branches

- To look at all **local** branches/see which branch you have checked out:

`git branch`

- To create a new branch:

`git checkout -b `

This will create a branch off of whatever you currently have checked out when you run the command.

- To switch branches (to an already existing branch):

`git checkout `

- To rename a branch:

`git branch -m `

- To update the list of branches on your local machine to match what's on the origin:

`git fetch --prune origin`

- To delete a branch:

`git branch -d `

Commands related to pushing/pulling changes

- To pull:

`git pull origin `

- To stage files:

`git add `

- To stage all changed files:

`git add *`

- To unstage a file:

`git restore --staged `

- To undo all changes you made to an unstaged file (reverts back to whatever the file looked like when you first checked out the branch):

`git restore `

- To see unstaged and staged changes:

`git status`

- To see what you've changed in a file:

`git diff `

- To add a commit (will commit any staged files):

`git commit -m "Your commit message here"`

- To go back one commit (before pushing):

`git reset HEAD~1`

- To see the git commit history:

`git log` (press `q` to exit and use the arrow keys to navigate up and down)

- To push a commit to your origin (likely GitHub or GitLab):

`git push origin `