If you’re new to Git or need a quick reference guide, this cheat sheet provides an extensive list of Git commands organized by category. Whether you’re just starting out or are a seasoned Git user, this cheat sheet is a handy resource for everyday Git use.
The cheat sheet includes commands for setting up a repository, staging changes, committing changes, viewing changes and history, branching and merging, working with remote repositories, stashing changes, managing tags, configuring Git, and other miscellaneous commands.
To use this cheat sheet, simply find the category of command you’re looking for, and then locate the specific command you need. The cheat sheet provides a brief description of each command, along with its syntax and any options or arguments that can be used.
Whether you’re a beginner or an experienced Git user, this cheat sheet is a valuable resource for anyone working with Git on a regular basis. Use it as a quick reference guide, or print it out and keep it nearby for easy access.
Cheat Sheet
Repository Setup
Git Command
Description
git init
Initialize a new Git repository
git clone [url]
Clone an existing Git repository
git remote add [remote_name] [url]
Add a new remote repository
Staging Changes
Git Command
Description
git add [file]
Add a file or files to the staging area
git add .
Add all changes to the staging area
git reset [file]
Remove a file from the staging area
Committing Changes
Git Command
Description
git commit -m “[message]”
Commit changes to the repository
git commit -a -m “[message]”
Commit all changes (including deleted files) to the repository
git commit –amend
Amend the last commit with new changes
Viewing Changes
Git Command
Description
git status
Show the status of the repository
git diff
Show the differences between the working directory and the staging area
git diff –staged
Show the differences between the staging area and the repository
Viewing History
Git Command
Description
git log
Show the commit history
git log –graph –oneline –decorate –all
Show a graph of the commit history
Branching and Merging
Git Command
Description
git branch
List all branches in the repository
git branch [branch_name]
Create a new branch
git checkout [branch_name]
Switch to a different branch
git merge [branch_name]
Merge the specified branch into the current branch
git rebase [branch_name]
Rebase the current branch on top of another branch
git cherry-pick [commit_hash]
Apply a specific commit from another branch
git branch -d [branch_name]
Delete a branch
Remote Repositories
Git Command
Description
git push [remote_name] [branch_name]
Push the current branch to a remote repository
git pull [remote_name] [branch_name]
Pull changes from a remote repository
git fetch [remote_name]
Fetch changes from a remote repository
git remote show [remote_name]
Show information about a remote repository
git remote remove [remote_name]
Remove a remote repository
Stashing Changes
Git Command
Description
git stash
Stash changes in a dirty working directory
git stash list
List stashed changes
git stash apply
Apply the most recent stash
git stash apply [stash_name]
Apply a specific stash
Tags
Git Command
Description
git tag [tag_name]
Create a new tag at the current commit
git tag -a [tag_name] -m “[message]”
Create an annotated tag with a message
git push [remote_name] –tags
Push all tags to a remote repository
Configuration
Git Command
Description
git config –global user.name “[name]”
Set the name associated with Git commits
git config –global user.email “[email]”
Set the email associated with Git commits
git config –global core.editor “[editor]”
Set the text editor used by Git
git config –global color.ui auto
Enable colored output for Git commands
Miscellaneous
Git Command
Description
git rm [file]
Remove a file from the repository
git mv [old_file] [new_file]
Rename a file in the repository
git blame [file]
Show the author and last modified time of each line in a file