🧠 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 init
Create a new Git repo git clone URL
Copy repo from GitHub git status
See current changes git add .
Stage all files git commit -m "msg"
Save changes git push origin main
Upload to GitHub git pull
Download + merge git log
View commit history git diff
Show file differences git reset
Undo commits git rm
Delete a file from Git
🌿 Working with Branches
Command Action git branch
List branches git checkout -b new-feature
Create and switch to a branch git checkout main
Switch to main git merge feature
Merge a branch git branch -d branch
Delete 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 -- file
Discard unstaged changes git reset HEAD file
Unstage file git revert <commit>
Revert a commit with history git reset --hard HEAD~1
Danger! Reset to 1 commit ago git stash
Save current uncommitted changes
🛠️ Advanced Git Features
Feature Command Tagging versions git tag v1.0.0
Cherry-pick commit git cherry-pick <commit-id>
Rebase branch git rebase main
Stash apply git stash apply
Remove 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 repo
Run 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-forward
Do 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.
Leave a Reply