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
- ๐ง Setup
- โ๏ธ Configuration Files
- ๐ Create Repository
- ๐ Local Changes
- ๐ Search
- ๐ Commit History
- ๐ Move / Rename
- ๐ฟ Branches & Tags
- ๐ Update & Publish
- ๐ Merge & Rebase
- โฉ๏ธ Undo
- ๐ Git Flow
- ๐ Other Languages
Show current configuration:
git config --listShow repository configuration:
git config --local --listShow global configuration:
git config --global --listShow system configuration:
git config --system --listSet your name for version history:
git config --global user.name "[firstname lastname]"Set your email address:
git config --global user.email "[valid-email]"Enable automatic command line coloring:
git config --global color.ui autoSet global editor for commits:
git config --global core.editor vi| Scope | Location | Command Flag | 
|---|---|---|
| Repository | <repo>/.git/config | --local | 
| User | ~/.gitconfig | --global | 
| System | /etc/gitconfig | --system | 
Via SSH:
git clone ssh://user@domain.com/repo.gitVia HTTPS:
git clone https://domain.com/user/repo.gitCreate repository in current directory:
git initCreate repository in specific directory:
git init <directory>View working directory status:
git statusShow changes to tracked files:
git diffShow changes in specific file:
git diff <file>Add all current changes:
git add .Add specific files:
git add <filename1> <filename2>Interactively add parts of a file:
git add -p <file>Commit all tracked file changes:
git commit -aCommit staged changes:
git commitCommit 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>"
โ ๏ธ Warning: Don't amend published commits!
Amend last commit:
git commit -a --amendAmend without changing commit message:
git commit --amend --no-editChange committer date:
GIT_COMMITTER_DATE="date" git commit --amendChange author date:
git commit --amend --date="date"Save current changes temporarily:
git stashApply last stashed changes:
git stash applyApply specific stash:
git stash apply stash@{stash_number}Use
git stash listto see available stashes
Remove last stash:
git stash dropMove uncommitted changes to another branch:
git stash
git checkout branch2
git stash popSearch for text in all files:
git grep "Hello"Search in specific version:
git grep "Hello" v2.5Find commits that introduced specific keyword:
git log -S 'keyword'Search with regular expression:
git log -S 'keyword' --pickaxe-regexShow all commits (detailed):
git logShow commits (one line each):
git log --onelineShow commits by specific author:
git log --author="username"Show changes for specific file:
git log -p <file>Compare branches:
git log --oneline <origin/master>..<remote/master> --left-rightShow who changed what and when:
git blame <file>Show reference log:
git reflog showDelete reference log:
git reflog deleteRename a file:
git mv Index.txt Index.htmlList local branches:
git branchList all branches (local + remote):
git branch -aList remote branches:
git branch -rList merged branches:
git branch --mergedSwitch to existing branch:
git checkout <branch>Create and switch to new branch:
git checkout -b <branch>Switch to previous branch:
git checkout -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:
git branch <new-branch>Create tracking branch:
git branch --track <new-branch> <remote-branch>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:
git branch -d <branch>Force delete local branch:
git branch -D <branch>
โ ๏ธ Warning: You will lose unmerged changes!
Create tag at HEAD:
git tag <tag-name>Create annotated tag:
git tag -a <tag-name>Create tag with message:
git tag <tag-name> -am 'message here'List all tags:
git tagList tags with messages:
git tag -nList configured remotes:
git remote -vShow remote information:
git remote show <remote>Add new remote:
git remote add <remote> <url>Rename remote:
git remote rename <remote> <new_remote>Remove remote:
git remote rm <remote>โน๏ธ Note: This only removes the remote reference locally, not the remote repository itself.
Download changes without merging:
git fetch <remote>Download and merge changes:
git pull <remote> <branch>Get changes from main branch:
git pull origin masterPull with rebase:
git pull --rebase <remote> <branch>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:
git push --tagsMerge branch into current HEAD:
git merge <branch>Configure merge tool globally:
git config --global merge.tool meldUse configured merge tool:
git mergetool
โ ๏ธ Warning: Don't rebase published commits!
Rebase current HEAD onto branch:
git rebase <branch>Abort rebase:
git rebase --abortContinue rebase after resolving conflicts:
git rebase --continueMark file as resolved:
git add <resolved-file>Remove resolved file:
git rm <resolved-file>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>
Discard all local changes:
git reset --hard HEADUnstage all files:
git reset HEADDiscard changes in specific file:
git checkout HEAD <file>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/masterReset preserving changes as unstaged:
git reset <commit>Reset preserving uncommitted local changes:
git reset --keep <commit>Revert commit (create new commit with opposite changes):
git revert <commit>Remove accidentally committed files that should be ignored:
git rm -r --cached .
git add .
git commit -m "remove ignored files"Improved Git-flow: git-flow-avh
- ๐ง Setup
- ๐ Getting Started
- โจ Features
- ๐ Make a Release
- ๐ฅ Hotfixes
- ๐ Commands Overview
Prerequisite: Working Git installation required. Git-flow works on macOS, Linux, and Windows.
macOS (Homebrew):
brew install git-flow-avhmacOS (MacPorts):
port install git-flowLinux (Debian-based):
sudo apt-get install git-flowWindows (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> | bashGit-flow needs initialization to customize your project setup.
Initialize (interactive):
git flow initYou'll answer questions about branch naming conventions. Default values are recommended.
Initialize (use defaults):
git flow init -dFeatures are for developing new functionality for upcoming releases. They typically exist only in developer repositories.
Start new feature:
git flow feature start MYFEATURECreates feature branch based on 'develop' and switches to it
Finish feature:
git flow feature finish MYFEATUREThis will:
- Merge MYFEATURE into 'develop'
- Remove the feature branch
- Switch back to 'develop'
Publish feature (for collaboration):
git flow feature publish MYFEATUREGet published feature:
git flow feature pull origin MYFEATURETrack origin feature:
git flow feature track MYFEATUREReleases 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 RELEASETrack remote release:
git flow release track RELEASEFinish release:
git flow release finish RELEASEThis 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 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 VERSIONMerges back into both 'develop' and 'master', and tags the master merge
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 | 
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
This project is open source and available under the MIT License.
โญ Star this repository if you found it helpful!
 git and git flow cheat sheet
 git and git flow cheat sheet
      

