đ About
This comprehensive Git cheat sheet helps you master Git commands without memorizing everything. Whether you're a beginner or an experienced developer, this guide provides quick reference to essential Git operations.
Contributions Welcome! Feel free to:
- Fix grammar mistakes
- Add new commands
- Translate to your language
- Improve explanations
đ Table of Contents
- đ§ Setup
- âī¸ Configuration Files
- đ Create Repository
- đ Local Changes
- đ Search
- đ Commit History
- đ Move / Rename
- đŋ Branches & Tags
- đ Update & Publish
- đ Merge & Rebase
- âŠī¸ Undo
- đ Git Flow
- đ Other Languages
đ§ Setup
View Configuration
Show current configuration:
Show repository configuration:
git config --local --list
Show global configuration:
git config --global --list
Show system configuration:
git config --system --list
User Configuration
Set your name for version history:
git config --global user.name "[firstname lastname]"Set your email address:
git config --global user.email "[valid-email]"Display & Editor Settings
Enable automatic command line coloring:
git config --global color.ui auto
Set global editor for commits:
git config --global core.editor vi
âī¸ Configuration Files
| Scope | Location | Command Flag |
|---|---|---|
| Repository | <repo>/.git/config |
--local |
| User | ~/.gitconfig |
--global |
| System | /etc/gitconfig |
--system |
đ Create Repository
Clone Existing Repository
Via SSH:
git clone ssh://user@domain.com/repo.git
Via HTTPS:
git clone https://domain.com/user/repo.git
Initialize New Repository
Create repository in current directory:
Create repository in specific directory:
đ Local Changes
Check Status & Differences
View working directory status:
Show changes to tracked files:
Show changes in specific file:
Staging Changes
Add all current changes:
Add specific files:
git add <filename1> <filename2>
Interactively add parts of a file:
Committing Changes
Commit all tracked file changes:
Commit staged changes:
Commit with message:
git commit -m 'message here'Skip staging and commit with message:
git commit -am 'message here'Commit with specific date:
git commit --date="`date --date='n day ago'`" -am "<Commit Message Here>"
Modify Last Commit
â ī¸ Warning: Don't amend published commits!
Amend last commit:
Amend without changing commit message:
git commit --amend --no-edit
Change committer date:
GIT_COMMITTER_DATE="date" git commit --amendChange author date:
git commit --amend --date="date"Stashing Changes
Save current changes temporarily:
Apply last stashed changes:
Apply specific stash:
git stash apply stash@{stash_number}Use
git stash listto see available stashes
Remove last stash:
Move uncommitted changes to another branch:
git stash git checkout branch2 git stash pop
đ Search
Text Search
Search for text in all files:
Search in specific version:
Commit Search
Find commits that introduced specific keyword:
Search with regular expression:
git log -S 'keyword' --pickaxe-regexđ Commit History
Basic History
Show all commits (detailed):
Show commits (one line each):
Show commits by specific author:
git log --author="username"Show changes for specific file:
Advanced History
Compare branches:
git log --oneline <origin/master>..<remote/master> --left-right
Show who changed what and when:
Reference Logs
Show reference log:
Delete reference log:
đ Move / Rename
Rename a file:
git mv Index.txt Index.html
đŋ Branches & Tags
List Branches
List local branches:
List all branches (local + remote):
List remote branches:
List merged branches:
Switch & Create Branches
Switch to existing branch:
Create and switch to new branch:
Switch to previous branch:
Create branch from existing branch:
git checkout -b <new_branch> <existing_branch>
Create branch from specific commit:
git checkout <commit-hash> -b <new_branch_name>
Create branch without switching:
Create tracking branch:
git branch --track <new-branch> <remote-branch>
Branch Operations
Checkout single file from different branch:
git checkout <branch> -- <filename>
Apply specific commit from another branch:
git cherry-pick <commit hash>
Rename current branch:
git branch -m <new_branch_name>
Delete local branch:
Force delete local branch:
â ī¸ Warning: You will lose unmerged changes!
Tags
Create tag at HEAD:
Create annotated tag:
Create tag with message:
git tag <tag-name> -am 'message here'
List all tags:
List tags with messages:
đ Update & Publish
Remote Management
List configured remotes:
Show remote information:
Add new remote:
git remote add <remote> <url>
Rename remote:
git remote rename <remote> <new_remote>
Remove remote:
âšī¸ Note: This only removes the remote reference locally, not the remote repository itself.
Fetch & Pull
Download changes without merging:
Download and merge changes:
git pull <remote> <branch>
Get changes from main branch:
Pull with rebase:
git pull --rebase <remote> <branch>
Push & Publish
Publish local changes:
git push <remote> <branch>
Delete remote branch:
# Git v1.7.0+ git push <remote> --delete <branch> # Git v1.5.0+ git push <remote> :<branch>
Publish tags:
đ Merge & Rebase
Merge Operations
Merge branch into current HEAD:
Configure merge tool globally:
git config --global merge.tool meld
Use configured merge tool:
Rebase Operations
â ī¸ Warning: Don't rebase published commits!
Rebase current HEAD onto branch:
Abort rebase:
Continue rebase after resolving conflicts:
Conflict Resolution
Mark file as resolved:
Remove resolved file:
Squashing Commits
Interactive rebase for squashing:
git rebase -i <commit-just-before-first>
Example squash configuration:
# Before
pick <commit_id>
pick <commit_id2>
pick <commit_id3>
# After (squash commit_id2 and commit_id3 into commit_id)
pick <commit_id>
squash <commit_id2>
squash <commit_id3>
âŠī¸ Undo
Discard Changes
Discard all local changes:
Unstage all files:
Discard changes in specific file:
Reset Operations
Reset to previous commit (discard all changes):
git reset --hard <commit>
Reset to remote branch state:
git reset --hard <remote/branch> # Example: git reset --hard upstream/master
Reset preserving changes as unstaged:
Reset preserving uncommitted local changes:
git reset --keep <commit>
Revert Commits
Revert commit (create new commit with opposite changes):
Clean Ignored Files
Remove accidentally committed files that should be ignored:
git rm -r --cached . git add . git commit -m "remove ignored files"
đ Git Flow
Improved Git-flow: git-flow-avh
đ Table of Contents
- đ§ Setup
- đ Getting Started
- ⨠Features
- đ Make a Release
- đĨ Hotfixes
- đ Commands Overview
đ§ Setup {#setup-1}
Prerequisite: Working Git installation required. Git-flow works on macOS, Linux, and Windows.
macOS (Homebrew):
brew install git-flow-avh
macOS (MacPorts):
Linux (Debian-based):
sudo apt-get install git-flow
Windows (Cygwin):
Requires wget and util-linux
wget -q -O - --no-check-certificate https://raw.githubusercontent.com/petervanderdoes/gitflow/develop/contrib/gitflow-installer.sh install <state> | bash
đ Getting Started
Git-flow needs initialization to customize your project setup.
Initialize (interactive):
You'll answer questions about branch naming conventions. Default values are recommended.
Initialize (use defaults):
⨠Features
Features are for developing new functionality for upcoming releases. They typically exist only in developer repositories.
Start new feature:
git flow feature start MYFEATURE
Creates feature branch based on 'develop' and switches to it
Finish feature:
git flow feature finish MYFEATURE
This will:
- Merge MYFEATURE into 'develop'
- Remove the feature branch
- Switch back to 'develop'
Publish feature (for collaboration):
git flow feature publish MYFEATURE
Get published feature:
git flow feature pull origin MYFEATURE
Track origin feature:
git flow feature track MYFEATURE
đ Make a Release
Releases support preparation of new production releases, allowing minor bug fixes and preparing meta-data.
Start release:
git flow release start RELEASE [BASE]
Creates release branch from 'develop'. Optionally specify [BASE] commit SHA-1.
Publish release:
git flow release publish RELEASE
Track remote release:
git flow release track RELEASE
Finish release:
git flow release finish RELEASE
This will:
- Merge release branch into 'master'
- Tag the release
- Back-merge release into 'develop'
- Remove release branch
đĄ Don't forget: Push your tags with
git push --tags
đĨ Hotfixes
Hotfixes address critical issues in live production versions. They branch off from the corresponding tag on master.
Start hotfix:
git flow hotfix start VERSION [BASENAME]
Finish hotfix:
git flow hotfix finish VERSION
Merges back into both 'develop' and 'master', and tags the master merge
đ Commands Overview
đ Git Flow Schema
đ Other Languages
This cheat sheet is available in multiple languages:
| Language | Link |
|---|---|
| đ¸đĻ Arabic | git-cheat-sheet-ar.md |
| đ§đŠ Bengali | git-cheat-sheet-bn.md |
| đ§đˇ Brazilian Portuguese | git-cheat-sheet-pt_BR.md |
| đ¨đŗ Chinese | git-cheat-sheet-zh.md |
| đŠđĒ German | git-cheat-sheet-de.md |
| đŦđˇ Greek | git-cheat-sheet-el.md |
| đŽđŗ Hindi | git-cheat-sheet-hi.md |
| đ°đˇ Korean | git-cheat-sheet-ko.md |
| đĩđą Polish | git-cheat-sheet-pl.md |
| đĒđ¸ Spanish | git-cheat-sheet-es.md |
| đšđˇ Turkish | git-cheat-sheet-tr.md |
đ¤ Contributing
We welcome contributions! You can:
- đ Report bugs or typos
- ⨠Add new Git commands
- đ Translate to new languages
- đĄ Improve explanations
- đ Enhance formatting
How to contribute:
- Fork this repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
đ License
This project is open source and available under the MIT License.
â Star this repository if you found it helpful!


