DEV Community

Cover image for 🧠 Master Git Like a Pro: A Developer’s Go-To Sheet
A.Satya Prakash
A.Satya Prakash

Posted on

🧠 Master Git Like a Pro: A Developer’s Go-To Sheet

“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
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

🔹 Commit Your Work

git commit -m "Short, clear message"
Enter fullscreen mode Exit fullscreen mode

🔹 Check the Status of Things

git status
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

🌿 Branching Like a Boss
🔹 Create a Branch

git branch feature-login
Enter fullscreen mode Exit fullscreen mode

🔹 Switch to It

git checkout feature-login
Enter fullscreen mode Exit fullscreen mode

🔹 Do Both at Once

git checkout -b feature-login
Enter fullscreen mode Exit fullscreen mode

🔹 Merge Changes Back In

git merge feature-login
Enter fullscreen mode Exit fullscreen mode

Tip: Always pull before merging to avoid drama.

☁️ Push and Pull from Remotes
🔹 Push Local Commits to GitHub

git push origin mainaAAAAA
Enter fullscreen mode Exit fullscreen mode

🔹 Pull Latest Changes from Remote

git pull origin main
Enter fullscreen mode Exit fullscreen mode

🔍 Commit History and Logs

git log
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

🔹 Unstage Changes (But Don’t Delete Them)

git reset --mixed HEAD~1
Enter fullscreen mode Exit fullscreen mode

🔹 Wipe Everything Back (⚠️ DANGER ZONE)

git reset --hard HEAD~1
Enter fullscreen mode Exit fullscreen mode

🔹 Rebase Like a Pro

git rebase main
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

🔹 Pick Just One Commit From Another Branch

git cherry-pick <commit-hash>
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (1)

Collapse
 
rakshitha_4 profile image
Rakshitha

Useful⚡