Git and Git Flow Cheat Sheet
đ 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:
git config --list
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://[email protected]/repo.git
Via HTTPS:
git clone https://domain.com/user/repo.git
Initialize New Repository
Create repository in current directory:
git init
Create repository in specific directory:
git init <directory>
đ Local Changes
Check Status & Differences
View working directory status:
git status
Show changes to tracked files:
git diff
Show changes in specific file:
git diff <file>
Staging Changes
Add all current changes:
git add .
Add specific files:
git add <filename1> <filename2>
Interactively add parts of a file:
git add -p <file>
Committing Changes
Commit all tracked file changes:
git commit -a
Commit staged changes:
git commit
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:
git commit -a --amend
Amend without changing commit message:
git commit --amend --no-edit
Change committer date:
GIT_COMMITTER_DATE="date" git commit --amend
Change author date:
git commit --amend --date="date"
Stashing Changes
Save current changes temporarily:
git stash
Apply last stashed changes:
git stash apply
Apply specific stash:
git stash apply stash@{stash_number}
Use
git stash listto see available stashes
Remove last stash:
git stash drop
Move uncommitted changes to another branch:
git stash
git checkout branch2
git stash pop
đ Search
Text Search
Search for text in all files:
git grep "Hello"
Search in specific version:
git grep "Hello" v2.5
Commit Search
Find commits that introduced specific keyword:
git log -S 'keyword'
Search with regular expression:
git log -S 'keyword' --pickaxe-regex
đ Commit History
Basic History
Show all commits (detailed):
git log
Show commits (one line each):
git log --oneline
Show commits by specific author:
git log --author="username"
Show changes for specific file:
git log -p <file>
Advanced History
Compare branches:
git log --oneline <origin/master>..<remote/master> --left-right
Show who changed what and when:
git blame <file>
Reference Logs
Show reference log:
git reflog show
Delete reference log:
git reflog delete
đ Move / Rename
Rename a file:
git mv Index.txt Index.html
đŋ Branches & Tags
List Branches
List local branches:
git branch
List all branches (local + remote):