Git Cheat Sheet

Kazi Zaber
3 min readDec 3, 2023

Need a π’ˆπ’Šπ’• 𝒄𝒉𝒆𝒂𝒕 𝒔𝒉𝒆𝒆𝒕?

1. π‘ͺ𝒐𝒓𝒆:
β€’ git init [initialize git repo]
β€’ git clone [clone a remote repo]
β€’ git add [add file(s) in git]
β€’ git commit [save the current state of the file]
β€’ git status [show uncommitted changes]
β€’ git diff [view the changes]
β€’ git reset [reset current HEAD to the specified state]
β€’ git log [show commit logs]
β€’ git show [shows one or more objects (blobs, trees, tags and commits)]
β€’ git tag [create, list, delete, or verify a tag object signed with GPG]
β€’ git push [update remote (should pull first after a commit)]
β€’ git pull [Fetch and merge (from remote/local)]
β€’ git checkout [switch branches or restore working tree files]

2. π‘©π’“π’‚π’π’„π’‰π’Šπ’π’ˆ:
β€’ git branch [show branch list, create, or delete branches]
β€’ git merge [join two or more histories together]
β€’ git rebase [reapply commits on top of another base tip]
β€’ git checkout -b | -B [create a new branch if not exist (reset if -B)]
β€’ git branch β€” set-upstream-to=<upstream> [reassign upstream]
β€’ git branch β€” unset-upstream [Remove the upstream information]
β€’ git cherry-pick [chose a commit from one branch and apply to another (cousin of merge, rebase)]

3. π‘΄π’†π’“π’ˆπ’Šπ’π’ˆ:
β€’ git merge [join two or more histories together]
β€’ git rebase [reapply commits on top of another base tip]

4. π‘Ίπ’•π’‚π’”π’‰π’Šπ’π’ˆ:
β€’ git stash [dump the changes (recoverable)]
β€’ git stash pop [remove a single stash and apply]
β€’ git stash list [show list the stash entries]
β€’ git stash apply [apply a stashed change]
β€’ git stash drop [remove a single stash entry]

5. π‘Ήπ’†π’Žπ’π’•π’†π’”:
β€’ git remote [manage a set of tracked repos]
β€’ git remote add [add a remote with the name]
β€’ git remote remove [remove the remote named <name>]
β€’ git fetch [download from another repo]
β€’ git pull [Fetch and merge (from remote/local)]
β€’ git push [update remote (should pull first after a commit)]
β€’ git clone β€” mirror[mirror source repo (maps all refs)]

6. π‘ͺπ’π’π’‡π’Šπ’ˆπ’–π’“π’‚π’•π’Šπ’π’π’”:
β€’ git config [get and set options]
β€’ git config β€” local [write in repo’s .git/config file (default)]
β€’ git config β€” global [write in global ~/.gitconfig instead]

** To reset config, you need to check `git config β€” global β€” list` and call `git config β€” global β€” unset-all core.editor`

7. π‘·π’π’–π’Žπ’ƒπ’Šπ’π’ˆ:
β€’ git cat-file [provide contents of repo]
β€’ git checkout-index[copy files from the index to the working tree]
β€’ git commit-tree [create a new commit object]
β€’ git diff-tree [compares content and mode of blobs between two trees]
β€’ git for-each-ref [information of each ref]
β€’ git hash-object [compute object ID for an object]
β€’ git ls-files [list directory tree]
β€’ git ls-remote [list remote repo]
β€’ git merge-tree [merge without touching index or working tree]
β€’ git read-tree [read tree information into the index]
β€’ git rev-parse [pick out and massage parameters]
β€’ git show-branch [show branches and commits]
β€’ git show-ref [list references in local repo]
β€’ git symbolic-ref [read, modify and delete symbolic refs]
β€’ git tag β€” list [list tags. With optional <pattern> for pattern-matching]
β€’ git update-ref [update object name in ref]

8. π‘·π’π’“π’„π’†π’π’‚π’Šπ’:
β€’ git blame [show revision and author for each line of file]
β€’ git bisect [binary search to find bug starting to commit]
β€’ git checkout [switch branches or restore working tree files]
β€’ git commit [save the current state of file]]
β€’ git rebase [reapply commits on top of another base tip]
β€’ git reset [reset current HEAD to the specified state]
β€’ git diff [view the changes]
β€’ git fetch [download from another repo]
β€’ git grep [print lines matching a pattern]
β€’ git log [show commit logs]
β€’ git merge [join two or more histories together]
β€’ git push [update remote (should pull first after a commit)]
β€’ git show [shows one or more objects (blobs, trees, tags and commits)]
β€’ git tag [create, list, delete or verify a tag object signed with GPG]

9. π‘¨π’π’Šπ’‚π’”:
β€’ git config β€” global alias.<alias> <command>

10. π‘―π’π’π’Œπ’”:
β€’ git config β€” local core.hooksPath <path>

Git Official Documentation: 𝒉𝒕𝒕𝒑𝒔://π’ˆπ’Šπ’•-π’”π’„π’Ž.π’„π’π’Ž/

--

--