Git & GitHub Command Cheat Sheet: From Basics to Advanced
Whether you’re a beginner just getting started with Git or an experienced developer who needs quick reference, this Git & GitHub Cheat Sheet has you covered.

🔹 Basic Workflow
=> These are the everyday Git commands you’ll use to track changes and sync with GitHub:
git init→ Initialize a new Git repositorygit clone [url]→ Download a project from GitHubgit add [file]→ Stage a specific file for commitgit add .→ Stage all changes for commitgit commit -m "message"→ Commit staged changesgit push origin [branch]→ Push commits to remotegit pull origin [branch]→ Pull latest changes
🔹 Branch Masters
=> Branching lets you work on features independently without affecting main code:
git branch→ List all branchesgit branch [name]→ Create new branchgit checkout [branch]→ Switch to branchgit merge [branch]→ Merge branch into currentgit branch -d [branch]→ Delete branch locallygit push origin --delete [branch]→ Delete remote branch
🔹 History Explorers
=> Explore and understand the history of your codebase:
git log --oneline→ Compact commit historygit log --graph --oneline --all→ Visual commit treegit show [commit]→ Show changes in specific commitgit diff→ Show unstaged changesgit diff --staged→ Show staged changesgit blame [file]→ See who changed each line
🔹 Undo Artists
=> Made a mistake? No worries, Git’s got your back:
git reset --soft HEAD^→ Undo commit, keep changes stagedgit reset --hard HEAD^→ Remove last commit completelygit checkout -- [file]→ Discard changes in working directorygit revert [commit]→ Create new commit that undoes changesgit clean -fd→ Remove untracked files & directories
🔹 GitHub Collaborators
=> For open-source contributions or working in teams:
git fork→ Create a personal copy of repositorygit remote add upstream [url]→ Add original repo as upstreamgit fetch upstream→ Get updates from original repogit push -u origin [branch]→ Push & set upstream branchgit pull --rebase upstream main→ Update fork with rebase
🔹 Stash & Cleanup
=> When you need to pause work without committing:
git stash→ Temporarily store changesgit stash pop→ Restore most recent stashgit stash list→ View all stashesgit stash drop→ Delete most recent stashgit prune→ Remove unreachable objects
🔹 Tagging & Releases
=> Tags are great for marking releases:
git tag [name]→ Create lightweight taggit tag -a [version] -m "message"→ Annotated taggit push origin --tags→ Push all tags to remotegit tag -d [name]→ Delete local taggit push origin --delete tag [name]→ Delete remote tag
🔹 Advanced Tools
=> Powerful commands for debugging and history management:
git bisect→ Binary search to find buggy commitgit rebase -i [commit]→ Interactive rebase (rewrite history)git cherry-pick [commit]→ Apply specific commit to current branchgit reflog→ Show reference log (lifesaver for recovery)git worktree add→ Add additional working trees
🔹 Configuration
=> Personalize Git to fit your workflow:
git config --global user.name "Name"→ Set global usernamegit config --global user.email "email"→ Set global emailgit config --global core.editor "code --wait"→ Use VS Code as editorgit config --global alias.co checkout→ Create shortcutsgit config --list→ Show all configurations
# Final Thoughts
Git is powerful, but it can feel overwhelming when you’re just starting out. Bookmark this cheat sheet and use it as a quick reference whenever you’re stuck.