Fantastic IT Tools
Web & Dev

Git Cheatsheet

Searchable reference of common git commands by topic.

47 results
git init
Setup

Create a new empty repository in the current directory.

git clone <url>
Setup

Clone a remote repository into a new directory.

git config --global user.name "Name"
Setup

Set the name attached to your commits.

git config --global user.email "[email protected]"
Setup

Set the email attached to your commits.

git status
Setup

Show changed, staged and untracked files.

git add <file>
Setup

Stage a file for the next commit (use . for all).

git commit -m "message"
Setup

Record staged changes with a message.

git commit -am "message"
Setup

Stage tracked changes and commit in one step.

git branch
Branching

List local branches.

git branch <name>
Branching

Create a new branch.

git switch <name>
Branching

Switch to an existing branch.

git switch -c <name>
Branching

Create and switch to a new branch.

git merge <branch>
Branching

Merge the named branch into the current one.

git branch -d <name>
Branching

Delete a fully merged branch.

git branch -D <name>
Branching

Force-delete a branch even if unmerged.

git restore <file>
Undo

Discard unstaged changes in a file.

git restore --staged <file>
Undo

Unstage a file but keep its changes.

git reset --soft HEAD~1
Undo

Undo last commit, keep changes staged.

git reset --hard HEAD~1
Undo

Undo last commit and discard its changes.

git revert <commit>
Undo

Create a new commit that undoes a given commit.

git commit --amend
Undo

Replace the last commit (edit message or add files).

git clean -fd
Undo

Remove untracked files and directories.

git remote -v
Remote

List configured remotes and their URLs.

git remote add origin <url>
Remote

Add a remote named origin.

git fetch
Remote

Download objects and refs without merging.

git pull
Remote

Fetch and integrate changes from the remote.

git push
Remote

Upload local commits to the remote.

git push -u origin <branch>
Remote

Push and set the upstream tracking branch.

git push --force-with-lease
Remote

Force-push safely, failing if remote advanced.

git stash
Stash

Save uncommitted changes and clean the working tree.

git stash push -m "msg"
Stash

Stash changes with a descriptive message.

git stash list
Stash

List all stashed change sets.

git stash pop
Stash

Apply the latest stash and remove it.

git stash apply
Stash

Apply a stash but keep it in the list.

git stash drop
Stash

Delete a single stash entry.

git log
Log

Show commit history.

git log --oneline --graph --all
Log

Compact graph of all branches.

git log -p <file>
Log

Show change history for a file with diffs.

git diff
Log

Show unstaged changes.

git diff --staged
Log

Show staged changes that will be committed.

git blame <file>
Log

Show who last modified each line of a file.

git show <commit>
Log

Show metadata and diff for a commit.

git rebase <branch>
Rebase

Reapply current commits on top of another branch.

git rebase -i HEAD~3
Rebase

Interactively squash/edit/reorder recent commits.

git rebase --continue
Rebase

Continue a rebase after resolving conflicts.

git rebase --abort
Rebase

Cancel an in-progress rebase.

git cherry-pick <commit>
Rebase

Apply a single commit onto the current branch.