Full list of Git commands: branches, commits, cherry-pick, rebase, stash and more

Git Cheatsheet ^-^

This is a complete guide with 100 Git commands.
From basics to advanced workflows β€” everything you need to feel like a Git Ninja πŸ₯·.

Basics

git init β€” create a new repository

git clone β€” clone a project

git status β€” check current changes

git add β€” add a file to staging

git add . β€” add all files

git commit -m “msg” β€” commit changes

git log β€” full commit history

git log –oneline β€” short history view

git show β€” details of a commit

git diff β€” show unstaged changes

Branches

git branch β€” list all branches

git branch β€” create a branch

git checkout β€” switch to a branch

git checkout -b β€” create and switch

git switch β€” switch branch (modern way)

git switch -c β€” create and switch (modern way)

git merge β€” merge a branch

git rebase β€” reapply commits on top

git branch -d β€” delete branch

git branch -D β€” force delete branch

Remote Repositories

git remote -v β€” show all remotes

git remote add origin β€” add a remote

git push origin β€” push branch to remote

git push -u origin β€” push and set upstream

git pull origin β€” pull from remote

git fetch β€” fetch changes without merging

git remote remove origin β€” remove a remote

git remote rename old new β€” rename a remote

git remote set-url origin β€” change remote URL

git push origin –delete β€” delete remote branch

Managing Changes

git diff –staged β€” compare staged changes

git reset β€” unstage a file

git reset –hard β€” reset to commit (delete changes)

git reset –soft β€” reset but keep changes

git revert β€” undo commit by new commit

git checkout – β€” restore file

git restore β€” modern restore file

git restore –staged β€” unstage file (modern way)

git commit –amend β€” edit last commit

git commit –amend -m “msg” β€” edit commit message

Stash

git stash β€” save changes temporarily

git stash list β€” list all stashes

git stash pop β€” restore last stash and delete it

git stash apply stash@{n} β€” apply specific stash

git stash drop stash@{n} β€” delete stash

git stash clear β€” delete all stashes

git stash save “msg” β€” save stash with message

git stash show β€” show stash changes

git stash branch β€” create branch from stash

git stash show -p β€” show patch of stash

Cherry-pick & Tags

git cherry-pick β€” apply commit from another branch

git cherry-pick -n β€” apply without commit

git cherry-pick –continue β€” continue after conflict

git cherry-pick –abort β€” stop cherry-pick

git tag β€” create tag

git tag -a -m “msg” β€” annotated tag

git push origin β€” push tag to remote

git push origin –tags β€” push all tags

git tag -d β€” delete tag locally

git push origin :refs/tags/ β€” delete tag remotely

Logs and History

git log –graph –oneline –all β€” graph view

git log –stat β€” show changes in each commit

git log –pretty=oneline β€” compact view

git log –pretty=format:"%h - %an, %ar : %s" β€” custom log format

git shortlog -sn β€” contributors list

git reflog β€” complete action history

git blame β€” show who edited each line

git annotate β€” similar to blame

git show-branch β€” show branch history

git whatchanged β€” show commits and changes

Advanced

git bisect start β€” start binary search for bug

git bisect bad β€” mark commit as bad

git bisect good β€” mark commit as good

git bisect reset β€” finish bisect

git clean -fd β€” delete untracked files

git clean -n β€” preview untracked delete

git submodule add β€” add submodule

git submodule update –init β€” initialize submodules

git submodule foreach git pull β€” update submodules

git archive –format=zip HEAD > file.zip β€” export project

Collaboration & Workflow

git fetch –all β€” fetch all branches

git pull –rebase β€” pull with rebase

git push –force β€” force push

git push –force-with-lease β€” safe force push

git rebase -i HEAD~n β€” interactive rebase

git merge –squash β€” squash merge

git rebase –abort β€” abort rebase

git rebase –continue β€” continue rebase

git merge –abort β€” abort merge

git cherry β€” show unmerged commits

Misc

git help β€” show help

git config –list β€” show config

git config –global user.name “Name” β€” set username

git config –global user.email “Email” β€” set email

git config core.editor “code –wait” β€” set editor

git init –bare β€” create bare repo

git archive β€” archive branch

git fsck β€” check integrity

git gc β€” clean up repository

gitk β€” open Git GUI

Key Points ^-^

100 commands cover 90% of daily and advanced Git usage

Don’t memorize, use this as a reference

Git is about save points, branches and history merging