Skip to content

Instantly share code, notes, and snippets.

@rubenhortas
Last active November 23, 2025 18:29
Show Gist options
  • Select an option

  • Save rubenhortas/c1019dc6e2d9484f7f54880d59b0c52f to your computer and use it in GitHub Desktop.

Select an option

Save rubenhortas/c1019dc6e2d9484f7f54880d59b0c52f to your computer and use it in GitHub Desktop.
git cheatsheet

git cheatsheet

User settings

Command Description
git config --global user.name $name Configure user name
git config --global user.email $mail Configure user email

Repository

Command Description
git init Create a new repository in the current directory
git clone $repository Download an existing repository from a remote url
git remote -v Show the URL of the remote repository

Branches

Command Description
git branch List existing branches
git branch $branch-name Create a new branch
git checkout -b $branch-name Create a new branch and switches to it
git push --set upstream $remote-repository $branch-name Create a local branch remotely
git switch $branch-name Switch to an existing branch
git fetch Retrieve updated branch information from the remote repository without merging them locally
git checkout $branch -- $file Get a file from a branch
git ls-files Show the tracked files
git merge Combine the history of another branch into the current branch
git merge --abort Aborts the current merge operation
git branch [-d|-D] $branch-name Delete a local branch.
-d deletes the branch if it has already fully merged.
-D deletes the branch regardless of its merged status
git push $origin --delete $branch-name Delete a remote branch
git rebase Reapplies commits from a branch on top of another branch (potentially rewriting history)

Changes

Add Changes

Command Description
git add (.|file) Add files to the staging area for the next commit
git rm [-rf] --cached ($file|$directory) Delete a file/directory from the staged area
git commit -ma $message Crete a new commit with a message
git commit --amend -m $message Correct the message from the last commit
git pull Fetch updates from the remote repository and attempts to merge them into the current local branch
git push [--follow-tags] Upload local commits to the remote repository
git blame Show who last modified each line of a file
git cherry pick Selectively applies a commit from another branch to the current branch

Tag changes

Command Description
git tag [-a|-d] $tag Create/delete a local tag for a specific commit
git tag -l [$regex] List tags
git show-ref --tags Show commits for all tags
git rev-list -n1 $tag Show which commit has a certain tag
git push --delete origin $tag && git tag -d $tag Delte a remote tag and, then, delete the local tag

Undo changes

Command Description
git checkout [file] Discard uncommited changes to the file
git reset [--hard] [file|commit] Move the HEAD pointer to a specific commit (hard removes local changes since then)
git reset --soft HEAD-1 Undo the last commit
git revert Create a new commit that undoes the changes introduced by another commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment