🧠 The Ultimate Git & GitHub Cheat Sheet (2025 Edition)
Everything You Need to Master Version Control in One Place
If you’re a developer, DevOps engineer, data scientist, or just someone managing code — Git and GitHub are tools you must know.
This cheat sheet is your one-stop guide to commands, workflows, concepts, and best practices — perfect for beginners or anyone who wants to refresh and level up.
Git & GitHub Cheat Sheet PDF
📌 What Are Git and GitHub?
Term Purpose Git A distributed version control system that tracks code changes, supports collaboration, and manages history. GitHub A cloud-based platform to host Git repositories with added features like issue tracking, pull requests, and CI/CD via GitHub Actions.
⚙️ Setting Up Git
✅ Install Git
✅ Configure Git
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Check configuration:
git config --list
🔁 Git Workflow Summary
1. git add → Stage changes
2. git commit → Commit snapshot
3. git push → Upload to GitHub
4. git pull → Sync with remote
🧱 Essential Git Commands
Command Description git initCreate a new Git repo git clone URLCopy repo from GitHub git statusSee current changes git add .Stage all files git commit -m "msg"Save changes git push origin mainUpload to GitHub git pullDownload + merge git logView commit history git diffShow file differences git resetUndo commits git rmDelete a file from Git
🌿 Working with Branches
Command Action git branchList branches git checkout -b new-featureCreate and switch to a branch git checkout mainSwitch to main git merge featureMerge a branch git branch -d branchDelete a branch
🌐 GitHub Collaboration Essentials
✅ Create a Repository
Go to https://github.com
Click New
Choose project name and visibility
✅ Connect Local Repo to GitHub
git remote add origin https://github.com/yourname/repo.git
git push -u origin main
✅ Fork + Pull Request Workflow
Fork a repo
Clone your fork
Create a branch → Commit → Push
Open a pull request (PR)
🔒 .gitignore & README
.gitignore – Exclude files like: node_modules/ .env *.log
README.md – Always document your repo purpose, usage, and license
🚨 Undoing Changes (Safety Tools)
Command Usage git checkout -- fileDiscard unstaged changes git reset HEAD fileUnstage file git revert <commit>Revert a commit with history git reset --hard HEAD~1Danger! Reset to 1 commit ago git stashSave current uncommitted changes
🛠️ Advanced Git Features
Feature Command Tagging versions git tag v1.0.0Cherry-pick commit git cherry-pick <commit-id>Rebase branch git rebase mainStash apply git stash applyRemove remote git remote remove origin
🧩 Key Git Concepts
Concept Explanation Staging Area Temporary space to prepare commits HEAD Current branch reference Fast-Forward Git just moves pointer if no divergence Detached HEAD Not on any branch – be cautious Origin Default name for remote GitHub repo
🚀 GitHub Features You Should Know
Feature Use Actions CI/CD pipelines Issues Bug & feature tracking Projects Kanban/task boards Discussions Community Q&A Wikis Collaborative documentation Pages Host static sites
📘 Best Practices
✅ Commit small, meaningful changes
✅ Pull before pushing
✅ Always work in a feature branch
✅ Use .gitignore and README.md
✅ Write clear commit messages
✅ Enable 2FA on GitHub
🧠 Common Git Errors and Fixes
Error Fix fatal: not a git repoRun in repo or git init Merge conflict Manually edit, then git add + git commit Permission denied (publickey)Add your SSH key to GitHub non-fast-forwardDo git pull --rebase before pushing
🧪 GitHub Tips for Teams
Use Protected Branches
Require Pull Requests before merge
Use CODEOWNERS to assign reviewers
Use Actions for automatic testing/deployments
Add badges in README (build passing, license, etc.)
📚 Cheat Sheet Resources
🏁 Final Words
Whether you’re writing solo projects or managing an enterprise CI/CD pipeline, Git + GitHub are tools you’ll use every day.
Master the basics. Learn to collaborate. Push fearlessly. Revert confidently. That’s the power of version control.