This content originally appeared on DEV Community and was authored by A.Satya Prakash
βAm I doing this right?β β Every developer using Git at some point.
Git is one of those tools that you must know if you are building anything with code from solo passion projects to massive team-based systems. But letβs face it, the commands can feel like arcane wizardry at first. After breaking enough things (and fixing them again), I decided to put together this practical Git cheatsheet to help myself and anyone else who wants to stop Googling the same stuff over and over.
Letβs be real: whether youβre pushing code to GitHub or just trying not to nuke your own project, Git is essential. Itβs not just a tool β itβs a habit, a mindset, a skill that separates amateurs from pros.
But it can also feel like you need to summon arcane magic just to undo a commit or rebase without panic. This blog is your no-BS guide to Git: from the basics to advanced moves, all wrapped in practical tips you can actually use β not just memorize.
Getting Started with Git
Initialize a New Git Repo
git init
Sets up Git in your project. Itβll quietly create a .git directory that tracks everything you do.
Clone a Remote Repo
git clone <repo-URL>
Grabs a full copy of someone else’s repo (or your own) from GitHub or anywhere else.
Staging, Committing, and Reviewing Changes
Stage Files
git add <filename> # Stage one file
git add . # Stage everything in the directory
Commit Your Work
git commit -m "Short, clear message"
Check the Status of Things
git status
See whatβs staged, whatβs changed, and whatβs untracked.
See What Changed
git diff # Changes not yet staged
git diff --cached # Changes that are staged
Branching Like a Boss
Create a Branch
git branch feature-login
Switch to It
git checkout feature-login
Do Both at Once
git checkout -b feature-login
Merge Changes Back In
git merge feature-login
Tip: Always pull before merging to avoid drama.
Push and Pull from Remotes
Push Local Commits to GitHub
git push origin mainaAAAAA
Pull Latest Changes from Remote
git pull origin main
Commit History and Logs
git log
Scroll through the history of commits, complete with author info and timestamps. Try git log –oneline for a cleaner view.
Advanced Git Tricks That Save You
Undo the Last Commit (But Keep Your Work)
git reset --soft HEAD~1
Unstage Changes (But Donβt Delete Them)
git reset --mixed HEAD~1
Wipe Everything Back (
DANGER ZONE)
git reset --hard HEAD~1
Rebase Like a Pro
git rebase main
Rewrites commit history to apply your changes cleanly on top of another branch. Useful for keeping things tidy.
Stash Your Work and Come Back Later
git stash # Save now
git stash apply # Bring it back
Pick Just One Commit From Another Branch
git cherry-pick <commit-hash>
Great for hotfixes or selective updates.
Git Hooks & Aliases (Power Moves)
Automate with Hooks
Inside .git/hooks, you can add shell scripts for things like:
pre-commit: Run linters or tests
post-merge: Run build scripts
Make sure the script is executable: chmod +x
Shortcuts with Git Aliases
git config --global alias.co checkout
git config --global alias.st status
git config --global alias.cm "commit -m"
Now you can use git co, git st, and git cm “message” to save time.
Git Workflows (Real-World Ready)
Centralized Workflow
- One main branch
- Everyone commits directly (best for small teams or solo)
Feature Branch Workflow
- Branch per feature
- Merge via pull requests (PRs)
- Keeps main stable
Gitflow Workflow
- main: Production-ready
- develop: Next release
- feature/*: New stuff
- release/*: Final polish
- hotfix/*: Emergency fixes
This works beautifully for larger teams or complex projects.
Save this blog. Share it. Use it every time you forget whether to reset, revert, or rebase.
This content originally appeared on DEV Community and was authored by A.Satya Prakash