Skip to content

Git Command Cheat Sheet

Terminal window
git status

Shows changed files, staged files, branch name, and whether there is anything to commit.

Terminal window
git clone https://github.com/organization/repository-name.git

Copies a GitHub repository to your computer.

Terminal window
git remote -v

Shows the remote repository URL.

Terminal window
git pull

Gets the latest commits from GitHub.

Terminal window
git checkout -b branch-name

or:

Terminal window
git switch -c branch-name

Creates and switches to a new branch.

Terminal window
git checkout main

or:

Terminal window
git switch main

Switches to another branch.

Terminal window
git branch

Shows local branches. The current branch has an asterisk.

Terminal window
git add filename

Prepares a file for the next commit.

Terminal window
git add .

Prepares all changed files in the current folder and below.

Use carefully. Beginners should often prefer staging specific files.

Terminal window
git commit -m "short message"

Saves staged changes as a local checkpoint.

Terminal window
git push -u origin branch-name

Sends a new branch to GitHub and connects the local branch to the remote branch.

Terminal window
git push

Sends local commits to GitHub.

Terminal window
git log

Shows previous commits.

For a shorter view:

Terminal window
git log --oneline
Terminal window
git status

Run this often.

Terminal window
git diff

Shows unstaged line-by-line changes.

Terminal window
git diff --staged

Shows staged line-by-line changes.

Beginners should ask for help before using:

Terminal window
git reset --hard
git push --force
git rebase
git clean -fd

These commands can discard work or rewrite history if used incorrectly.