đ§ 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.