Cheatography
https://cheatography.com
Quick summary with most important Git commands and key concepts.
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Configuration
Display all settings
|
git config --global user.name $user
Set user name
|
git config get user.email
Display user name
|
git config --global user.email $email
Set email address
|
Display email address
|
git config --global core.editor $editor
Set text editor
|
git config --global alias.$alias $cmd
Set alias for a command
|
git config --global init.defaultBranch $branch
Set default name for main branch
|
git config --global core.autocrlf true
Set end of line character (Windows). Default value
|
git config --global core.autocrlf input
Set end of line character (Linux/MacOs)
|
Initializing, Staging & Commiting
Print all commands available
|
Print command options
|
Open Git documentation in browser
|
Display Git version
|
Initialize working tree
|
Display state of working tree and index
|
Display summarized version
|
Stage file
|
Stage all changes recursively
|
Stage changes to match working tree
|
Commit changes with message
|
Commit no staged changes
|
Edit last commit message (CLEAN index)
|
Move to previous commit
|
Move/rename and stage
|
Remove file from tree and index
|
Remove file from index
|
Remove directory recursively from index
|
Logs
Display commit history
|
Display shortened commit history
|
Display n commits
|
Display changes, insertions & deletions
|
Show commited changes file by file
|
git log --all --decorate --oneline --graphic
Display commit history tree
|
git reflog --relative-date
Display command history
|
Display commit, author & date per line
|
Compare working tree and index
|
Compare file in working tree and index
|
Compare index and last commit
|
Compare working tree and last commit
|
Display changes in commit
|
Display file content in commit
|
Display files in index
|
git ls-tree --name-only HEAD
Display files in local repository
|
Branching
List local branches
|
List remote branches
|
List local and remote branches
|
Create branch
|
Create branch rooting from other
|
Rename branch
|
Delete branch
|
Delete NOT merged branch
|
Move to branch
|
Create branch and move
|
Move to branch
|
Move to previous branch
|
Create branch and move
|
Merge branch into current one
|
Remote Repositories
git remote add $alias $url
Add remote repository
|
List remote repositories
|
git remote rename $old $new
Rename remote repository
|
Clone remote repository
|
Clone remote repository to specific folder
|
Compare index and remote repository
|
Display commit history from remote repository
|
Download information from remote repository
|
Merge remote repository into current branch
|
Pull (fetch+merge) remote repository into current branch
|
Pull remote repository into specific branch
|
Push current branch into remote repository
|
Push specific branch into remote repository
|
git push --set-upstream $alias $branch
Push to remote repository and set it as default target for that branch
|
Display remote repository references
|
Undoing Changes
Retrieve file from last commit
|
Retrieve file from other commit
|
Retrieve file from index
|
git restore --staged $file
Retrieve index file from last commit
|
Create new commit that undoes last commit's changes
|
Revert specific commit
|
git revert HEAD --no-edit
Revert last commit skipping message editor
|
git revert HEAD~$n --no-edit
Revert n commits back skipping editor
|
Delete commit. Undo repo. Leave wd and index unchanged
|
Delete commit. Undo repo and index. Leave wd unchanged
|
Delete commit. Undo repo, index and wd
|
Advanced Topics
Move branch ancestor to other commit
|
Squash. Combine n commits into one
|
Append commit to current branch
|
Save wd and index to stash. Revert to last commit
|
List available stashs
|
Apply latest stash. Remove it from stack
|
Apply specific stash. Remove it from stack
|
Apply latest stash. Keep it in stack
|
Remove latest stash from stack
|
List tags
|
Create tag to current commit
|
Create tag with message
|
Create tag to specific commit
|
Push tags to remote repository
|
List working trees
|
Create linked tree
|
git worktree remove $tree
Delete tree
|
|
|
|