Git Reference & Cheatsheet — Complete Command Guide
Learning Path
flowchart LR
A["Git Overview"] --> B["Core Concepts"]
B --> C["Intermediate Topics"]
C --> D["Advanced Topics"]
D --> E["Practical Applications"]
A --> F["You Are Here"]
style F fill:#f90,color:#fff
This Git reference covers every essential command — from configuration and daily workflow to branching, remotes, undoing changes, and advanced features. Use it as a quick lookup alongside the full tutorials.
Configuration
git config --global user.name "Name"
git config --global user.email "email"
git config --global init.defaultBranch main
git config --global color.ui auto
git config --global core.editor nano
git config --global alias.lg "log --oneline --graph --decorate"
git config --list
git config user.name # view single valueGetting Help
git help <command>
git <command> --help
git <command> -h # concise helpCreating & Cloning Repos
git init # new empty repo
git clone URL # copy existing repo
git clone --depth 1 URL # shallow clone (faster)
git clone --recurse-submodules URL # include submodulesBasic Workflow
git status # show state
git status -sb # short + branch
git add <file> # stage file
git add . # stage all
git add -p # stage interactively (hunk by hunk)
git commit -m "message" # commit staged
git commit -am "message" # add + commit (tracked files only)
git commit --amend -m "new msg" # fix last commit message
git commit --amend --no-edit # add to last commit, keep messageViewing History
git log # full history
git log --oneline # compact
git log --graph # with branch graph
git log -p # with diffs
git log -n 5 # last 5 commits
git log --author="name" # filter by author
git log --since="2024-01-01" # filter by date
git log --grep="fix" # filter by message
git log --follow <file> # history of a file (incl. renames)
git show <commit> # show commit details + diffComparing Changes
git diff # unstaged changes
git diff --staged # staged changes
git diff <commit> <commit> # between two commits
git diff <branch>..<branch> # between branches
git diff HEAD~3 HEAD # 3 commits ago vs now
git blame <file> # who changed each lineBranching
git branch # list local branches
git branch -a # list all (local + remote)
git branch -v # with last commit
git branch <name> # create branch
git branch -d <name> # delete merged branch
git branch -D <name> # force delete unmerged
git branch -m <old> <new> # rename
git checkout <branch> # switch branch
git checkout -b <branch> # create + switch
git switch <branch> # switch (modern)
git switch -c <branch> # create + switch (modern)Merging
git merge <branch> # merge into current
git merge --no-ff <branch> # force merge commit
git merge --abort # abort conflicted merge
git mergetool # launch merge tool
git log --merge # show conflicting commitsRebasing
git rebase <branch> # replay commits on top
git rebase -i HEAD~3 # interactive (squash, reword, reorder)
git rebase --continue # continue after conflict resolution
git rebase --skip # skip a commit
git rebase --abort # cancel rebaseCherry-Pick
git cherry-pick <commit> # apply a specific commit
git cherry-pick <a> <b> # apply multiple
git cherry-pick <a>..<b> # apply range
git cherry-pick --no-commit <c> # stage changes only, don't commitStashing
git stash # save changes
git stash push -m "message" # save with message
git stash -u # include untracked files
git stash list # list stashes
git stash apply # apply latest stash (keep)
git stash pop # apply and remove
git stash apply stash@{2} # apply specific stash
git stash drop stash@{0} # drop specific stash
git stash clear # remove all stashes
git stash branch <name> # create branch from stashUndoing
git restore <file> # discard unstaged changes
git restore --staged <file> # unstage (keep changes)
git checkout -- <file> # discard (older syntax)
git reset HEAD~1 # undo last commit (keep changes)
git reset --soft HEAD~1 # undo last commit (keep staged)
git reset --hard HEAD~1 # undo + discard changes
git revert HEAD # new commit undoing last
git revert <commit> # new commit undoing specific
git clean -fd # remove untracked files/dirsRemotes
git remote -v # list remotes
git remote add <name> <url> # add remote
git remote remove <name> # remove remote
git remote rename <old> <new> # rename remote
git remote set-url <name> <url> # change URL
git remote show <name> # detailed info
git fetch <remote> # download objects/refs
git fetch --prune # fetch + prune deleted branches
git pull # fetch + merge
git pull --rebase # fetch + rebase
git push # push to tracked remote
git push -u origin <branch> # push + set upstream
git push --tags # push all tags
git push --force # force push (dangerous)
git push --force-with-lease # safer force push
git push origin --delete <branch> # delete remote branchTagging
git tag # list tags
git tag -a v1.0.0 -m "message" # annotated tag
git tag v1.0.0 # lightweight tag
git tag -d v1.0.0 # delete local
git push origin v1.0.0 # push specific tag
git push --tags # push all tags
git push origin --delete v1.0.0 # delete remote tag
git checkout v1.0.0 # checkout tag (detached)Reflog & Recovery
git reflog # show HEAD movements
git reflog <branch> # show branch movements
git reset --hard HEAD@{2} # reset to reflog entry
git checkout HEAD@{2} # checkout reflog entry
git branch recover <hash> # create branch at old commitAdvanced
git submodule add <url> <path> # add submodule
git submodule update --init # init + fetch submodules
git submodule update --remote # update to latest
git lfs install # init LFS
git lfs track "*.psd" # track large files
git lfs ls-files # list tracked files
git commit -S -m "msg" # sign commit
git tag -s v1.0.0 -m "msg" # sign tag
git bisect start # binary search for bug
git bisect bad # current is bad
git bisect good <commit> # mark known good commit
git blame <file> # show last modification per line
git shortlog -sn # contributors ranked by commits
git gc # garbage collection (optimize)
git fsck # check repository integrity
git archive --format=zip HEAD # export repo as zip
git bundle create file.bundle --all # bundle as single file
git clean -fd # remove untracked files/dirs
git describe # nearest tag to current HEADReset Modes Summary
| Mode | HEAD | Staging | Working Dir |
|---|---|---|---|
--soft | Moves | Kept | Unchanged |
--mixed | Moves | Cleared | Unchanged |
--hard | Moves | Cleared | Reverted |
Useful Aliases
git config --global alias.lg "log --oneline --graph --all --decorate"
git config --global alias.ci "commit"
git config --global alias.co "checkout"
git config --global alias.br "branch"
git config --global alias.st "status -sb"
git config --global alias.unstage "reset HEAD --"
git config --global alias.last "log -1 HEAD"
git config --global alias.visual "!gitk"Exit Codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Error (merge conflict, bad revision, etc.) |
| 128 | Fatal error (permission, no repo, etc.) |
Common Mistakes Beginners Make
1. Skipping the Fundamentals
Many beginners jump straight to advanced topics without mastering the basics. Take time to understand the core concepts before moving on.
2. Not Practicing Enough
Reading tutorials without writing code leads to shallow understanding. Code along with every example and experiment on your own.
3. Ignoring Error Messages
Error messages tell you exactly what went wrong. Read them carefully — they usually point to the line and type of issue.
4. Copy-Pasting Without Understanding
It’s tempting to copy code from tutorials, but typing it yourself and understanding each line builds real skill.
5. Giving Up Too Early
Every developer hits frustrating bugs. Take breaks, ask for help, and remember that struggling is part of learning.
FAQ
{< faq >}
- What is Git Reference?
- Git Reference refers to the core concepts and practices used to build and manage modern web applications. Understanding it is essential for web developers.
- Do I need prior experience to learn Git Reference?
- Basic familiarity with web development concepts helps, but Git Reference can be learned step by step even as a beginner.
- How long does it take to learn Git Reference?
- With consistent practice, you can grasp the fundamentals in a few days to a week. Mastery takes ongoing practice and real-world projects.
- Where can I use Git Reference in real projects?
- Git Reference is used in a wide range of applications — from simple websites to complex enterprise systems, depending on the specific tools and technologies involved.
- What are common tools used with Git Reference?
- The specific tools depend on the technology stack, but version control (Git), package managers, and testing frameworks are commonly used alongside most development topics.
{< /faq >}
What’s Next
Explore related references and tutorials:
| Topic | Description |
|---|---|
| https://tutorials.dodatech.com/devops/cloud/aws/reference/ | AWS services reference |
| https://tutorials.dodatech.com/tools/lodash/ | Lodash utility library |
Related topics to explore:
- Git Tutorials
- DevOps Tools
- Linux Command Line
What’s Next
Congratulations on completing this Git Reference tutorial! Here’s where to go from here:
- Practice daily — Consistency is more important than long study sessions
- Build a project — Apply what you learned by building something real
- Explore related topics — Check out other tutorials in the same category
- Join the community — Discuss with other learners and share your progress
Remember: every expert was once a beginner. Keep coding!
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro