Dtools
TXT-18

Git Command Cheatsheet

Searchable reference for common Git commands.

34 of 34 commands

Setup

git init

Create a new empty repository in the current directory.

git clone <url>

Copy an existing repository to your local machine.

git config --global user.name "name"

Set the name used in your commits.

Basics

git status

Show changed, staged, and untracked files.

git add <file>

Stage a file's changes for the next commit.

git add .

Stage all changes in the current directory.

git commit -m "message"

Record staged changes with a message.

git commit --amend

Edit the most recent commit instead of creating a new one.

git diff

Show unstaged changes compared to the last commit.

git diff --staged

Show staged changes compared to the last commit.

History

git log

Show commit history for the current branch.

git log --oneline --graph

Show a compact, graph-style commit history.

git show <commit>

Show the changes introduced by a specific commit.

git blame <file>

Show who last changed each line of a file.

Branching

git branch

List local branches.

git branch <name>

Create a new branch.

git switch <branch>

Switch to an existing branch.

git switch -c <branch>

Create a new branch and switch to it.

git merge <branch>

Merge another branch into the current branch.

git rebase <branch>

Reapply commits on top of another branch.

git branch -d <branch>

Delete a local branch (only if merged).

Remote

git fetch

Download commits and branches from a remote without merging.

git pull

Fetch from a remote and merge into the current branch.

git push

Upload local commits to a remote branch.

git push -u origin <branch>

Push a branch and set it to track the remote branch.

git remote -v

List remotes and their URLs.

Undo

git reset --soft HEAD~1

Undo the last commit but keep changes staged.

git reset --hard HEAD~1

Undo the last commit and discard the changes entirely.

git checkout -- <file>

Discard local changes to a file.

git revert <commit>

Create a new commit that undoes a previous commit.

git stash

Temporarily shelve uncommitted changes.

git stash pop

Re-apply the most recently stashed changes.

Tags

git tag <name>

Create a tag at the current commit.

git tag -a <name> -m "message"

Create an annotated tag with a message.

Related tools

More in Text Tools