Tool cheatsheet
Git 2 Cheatsheet
Everyday Git commands for committing, branching, syncing and undoing mistakes.
Getting started
- Check the Git version — Print the installed Git version.
- Set your name — Set the name recorded on your commits, for every repository on this machine.
- Set your email — Set the email recorded on your commits.
- Start a repository — Turn the current folder into a Git repository.
- Clone a repository — Download a repository and its full history.
- See what has changed — Show modified, staged and untracked files.
Committing
- Stage all changes — Stage every modified, new and deleted file in the current directory and below.
- Stage parts of a file — Choose which hunks of a file to stage.
- Commit staged changes — Record the staged changes with a message.
- Change the last commit message — Replace the message of the most recent commit.
- See unstaged changes — Show what changed since the last stage or commit.
- See staged changes — Show what will go into the next commit.
- View history compactly — Show one line per commit with the branch graph.
- Show a commit — Show the message and changes of the latest commit.
Branches
- List branches — Show local branches and mark the current one.
- Create and switch to a branch — Create a new branch from the current commit and switch to it.
- Switch branch — Move to an existing branch.
- Rename the current branch — Rename the branch you are on.
- Delete a merged branch — Delete a local branch that has been merged. Git refuses if it has unmerged work.
- Delete an unmerged branch — Delete a local branch even if its commits are not merged.
- Delete a remote branch — Remove a branch from the remote.
- Merge a branch — Merge another branch into the one you are on.
- Rebase onto another branch — Replay your commits on top of main.
Remotes
- Add a remote — Connect the repository to a remote named origin.
- List remotes — Show remote names and their URLs.
- Fetch without merging — Download new commits from all remotes and drop references to deleted branches.
- Pull with rebase — Fetch and replay your local commits on top, avoiding a merge commit.
- Push a new branch — Push the branch and set its upstream so later pushes need no arguments.
- Force push safely — Overwrite the remote branch only if nobody has pushed to it since you last fetched.
Undoing changes
- Discard changes to a file — Restore a file to its last committed state.
- Unstage a file — Remove a file from the staging area but keep your edits.
- Undo the last commit, keep the changes — Move the branch back one commit and leave the changes staged.
- Undo the last commit and discard the changes — Move the branch back one commit and throw away its changes.
- Revert a commit safely — Create a new commit that undoes an earlier one. Safe on shared branches.
- Find lost commits — List where HEAD has been, including commits no branch points to.
- Preview untracked files to delete — Show which untracked files and folders git clean would remove.
- Delete untracked files — Remove untracked files and folders.
Stash and history
- Stash your work — Set aside uncommitted changes with a label.
- List stashes — Show saved stashes, newest first, with the label you gave each.
- Restore the latest stash — Apply the newest stash and remove it from the list.
- Copy a commit to this branch — Apply the changes of one commit onto the current branch.
- Create an annotated tag — Tag the current commit, for example for a release.
- See who changed each line — Show the commit and author for every line of a file.
- Find commits that changed a string — List commits whose changes add or remove the given text.
- Find the commit that broke something — Start a binary search through history. Mark commits with git bisect good and git bisect bad.
Related cheatsheets
- Ansible 2 cheatsheet — Run ad-hoc commands and playbooks, manage inventories, roles, collections and secrets with Ansible.
- Argo CD 3 cheatsheet — Install Argo CD, define Applications declaratively, and manage sync, diffs, history and rollbacks with the argocd CLI.
- AWS CLI 2 cheatsheet — Configure credentials and manage S3, EC2, Lambda, logs, containers and secrets with the AWS CLI v2.
- Azure CLI 2 cheatsheet — Sign in and manage resource groups, VMs, web apps, storage, Kubernetes, registries and secrets with the az command.
- Bash and Linux 5 cheatsheet — Everyday shell and Linux commands for files, searching text, permissions, processes and servers.
- Claude API cheatsheet — Call Claude from Python, TypeScript or curl: messages, streaming, thinking, tools, structured output, caching, batches and error handling.