6 categories, 50+ commands · Visual workflow · 8 common scenarios · Git config best practices
git init
git clone <url>
git add <file>
git add .
git commit -m "message"
git status
git branch
git branch <name>
git checkout <branch>
git checkout -b <branch>
git merge <branch>
git branch -d <branch>
git remote -v
git remote add origin <url>
git push origin <branch>
git pull origin <branch>
git fetch origin
git restore <file>
git restore --staged <file>
git reset --soft HEAD^
git reset --hard HEAD^
git revert <commit>
git log
git log --oneline
git log --graph
git diff
git show <commit>
git stash
git stash pop
git rebase <branch>
git cherry-pick <commit>
git bisect
# Fix the last commit message
git commit --amend -m "new message"
# Add a missing file to the last commit
git add forgotten-file
git commit --amend --no-edit
# Stash current work
git stash save "feature in progress"
# Switch to another branch
git checkout bugfix
# After fixing, return
git checkout feature
git stash pop
# Safe way: revert (recommended)
git revert HEAD
git push origin main
# Force overwrite (use with caution)
git reset --hard HEAD^
git push --force origin main
# See which files conflict
git status
# After manually resolving
git add resolved-file
git commit -m "Resolve merge conflict"
# Or abort the merge
git merge --abort
# Show all operations
git reflog
# Find the last commit of the deleted branch
git checkout -b recovered-branch commit-id
# Interactive rebase
git rebase -i HEAD~3
# In the editor, change pick to squash (or s)
# Save and edit the new commit message
# Remove from Git but keep locally
git rm --cached filename
# Add to .gitignore
echo "filename" >> .gitignore
git add .gitignore
git commit -m "Stop tracking file"
# View all reference logs
git reflog
# Find the lost commit id
git checkout commit-id
# Or create a branch to keep it
git branch recovered-branch commit-id
| Setting | Command | Description |
|---|---|---|
| User name | git config --global user.name "Your Name" |
Set global username |
| User email | git config --global user.email "email@example.com" |
Set global email |
| Default editor | git config --global core.editor "code --wait" |
Set VS Code as default editor |
| Aliases | git config --global alias.co checkout |
Common command shortcuts |
| Line endings | git config --global core.autocrlf input |
Handle cross‑platform newlines |
| List config | git config --list |
Show all configuration |
Ideal for large projects with strict releases
Simple, continuous deployment
Environment branches + feature branches
Git is the most popular distributed version control system. Whether you're a solo developer or part of a team, mastering Git is essential. The ng.cc Git command cheatsheet covers initialization, commits, branches, remotes, undo, and history – 6 core categories with 50+ of the most used commands. It also includes a visual workflow diagram and 8 real‑world scenario solutions.
See how files move between Working Directory, Staging, Local Repo, and Remote Repo – no more abstract concepts.
Fix wrong commit messages, recover deleted branches, resolve conflicts, undo pushes – covers 90% of daily pain points.
Every command has a copy button – grab and use instantly.
Compare Git Flow, GitHub Flow, and GitLab Flow to choose the right collaboration model for your team.
git init creates a repo, git clone copies a remote one, git add stages changes, git commit saves them, git status shows the current state – your daily bread and butter.
git branch lists/creates branches, git checkout switches, git merge combines work. Use feature branches to keep main clean.
git push uploads commits, git pull downloads and merges, git fetch only downloads. Always pull before pushing to avoid conflicts.
git restore (new in 2.23+) discards local changes; git reset undoes commits locally; git revert safely undoes pushed commits. Git can recover almost anything.
git pull and git fetch?
git pull = git fetch + git merge. fetch only downloads updates; pull immediately merges them. Safer to fetch first, inspect, then merge manually.
git commit --amend. If already pushed, amend and then git push --force, but only if you're the only one using that branch. Avoid force‑pushing on shared branches.
reset, revert, and restore?
git reset: moves the HEAD pointer – for local undo.git revert: creates a new commit that undoes an old one – safe for shared history.git restore: discards changes in working directory or staging – doesn't alter history.git rm --cached filename to stop tracking it, then add to .gitignore.
git status to see conflicted files.<<<<<<<, =======, >>>>>>> markers. Keep the correct parts.git add the files.git commit to finish. Using a visual tool (VS Code, etc.) makes it easier.
git reflog recover lost commits?
git reflog records every movement of HEAD (resets, rebases, branch deletions). As long as the commit existed locally, you can find its ID and restore it. Entries are kept for 90 days by default.
This tool is part of the ng.cc developer version control toolkit. You might also need:
⚡ All commands are processed locally in your browser – no data ever uploaded.