Skip to main content

🚀 Git & GitHub Cheat Sheet: The Lazy Developer’s Survival Guide

Master Git. Conquer GitHub. Avoid "Where did my code go?" moments.

Updated 6 min readMarkdown
🚀 Git & GitHub Cheat Sheet: The Lazy Developer’s Survival Guide

🤔 Why Should You Even Care About Git & GitHub?

Imagine this: You’re working on a project, everything is going great, and then—BOOM!—you accidentally delete your code. Or worse, your teammate overwrites your work.

This is where Git and GitHub save the day. 💪

  • Git is like a time machine for your code. It helps you track changes, revert mistakes, and collaborate with others without screaming at your screen.

  • GitHub is the social media of Git—where you store, share, and collaborate on projects with developers around the world.

Whether you’re a college student, a beginner, or just someone who doesn’t want to lose their code, this cheat sheet is your best friend. Let’s go! 🚀


⚡ Core Git Commands (a.k.a. Your Day-to-Day Lifesavers)

CommandWhat It Does
git initCreates a new Git repo (inside a folder)
git clone <repo_url>Downloads a remote repo to your computer
git statusShows changes that need to be committed
git add <file>Stages a specific file for commit
git add .Stages all changes
git commit -m "message"Saves changes with a meaningful message
git push origin <branch>Uploads local changes to GitHub
git pull origin <branch>Updates your local branch with the latest changes
git fetch originChecks for updates on GitHub without merging them
git merge <branch>Combines changes from another branch into the current branch

📌 What’s the Difference Between git fetch and git pull?

  • git fetch only checks for updates from the remote repo but doesn’t apply them.

  • git pull fetches updates and merges them into your local branch automatically.


🌳 Branching Like a Pro

CommandWhat It Does
git branch <branch_name>Creates a new branch
git branchLists all local branches
git switch <branch_name>Switches to a branch (recommended)
git checkout <branch_name>Switches branches (older method)
git merge <branch>Merges changes from another branch
git rebase <branch>Reapplies commits on top of another branch
git branch -d <branch_name>Deletes a local branch
git push origin --delete <branch_name>Deletes a remote branch

🚀 Why Use Branches?

  • Keep your main branch clean and bug-free 🧼

  • Work on new features without messing up the main project

  • Test things out without affecting the main codebase


🔍 Finding & Fixing Mistakes

CommandWhat It Does
git logShows commit history
git log --onelineA compact version of commit history
git diffShows the difference between current and previous versions
git blame <file>Shows who last edited each line of a file
git reset <file>Unstages a file (removes from staging)
git reset --hard <commit>Rolls back to a previous commit (⚠️ Deletes all changes!)
git revert <commit>Creates a new commit that undoes changes from a previous commit

😱 What If You Mess Up?

  • For small mistakes: git reset <file> moves it back to unstaged.

  • For big mistakes: git revert is safer because it doesn’t delete history.

  • For catastrophic mistakes: git reflog helps you restore lost commits.


📌 Stashing: When You Need a Quick Save

CommandWhat It Does
git stashSaves uncommitted changes for later
git stash applyRe-applies the last stashed changes
git stash popRe-applies and deletes stash
git stash listShows all saved stashes

🚀 When to Use git stash?

  • If you need to switch branches quickly without committing unfinished work.

  • If your teammate says, “Hey, pull the latest changes first!” but you’re mid-edit.


🌎 GitHub-Specific Commands

CommandWhat It Does
git remote -vShows connected GitHub repositories
git remote add origin <repo_url>Links local repo to GitHub
git push --set-upstream origin <branch>Sets the remote branch for tracking
git forkCreates a copy of someone else’s repo under your account
git fetch upstreamSyncs changes from the original repo (useful for forks)
git pull upstream mainPulls the latest updates from the main project

🔥 GitHub CLI: Make Life Even Easier

CommandWhat It Does
gh auth loginLogs into GitHub from the terminal
gh repo create <name>Creates a new GitHub repo from the terminal
gh repo clone <repo>Clones a GitHub repo
gh pr createCreates a pull request
gh pr listLists open pull requests
gh issue createOpens a new issue

🤝 Collaborating with a Team

CommandWhat It Does
git pull origin mainGet the latest changes from the team
git merge feature-branchMerge a teammate’s feature into your branch
git cherry-pick <commit>Copy a specific commit from another branch
git revert <commit>Reverse a bad commit (without deleting history)

🚀 Pro Tips for Git & GitHub

🔥 1. Write Meaningful Commit Messages
Bad: git commit -m "fixed stuff" ❌
Good: git commit -m "Fixed login button alignment issue" ✅

🔥 2. Always Pull Before Pushing
Running git pull origin main before pushing prevents conflicts.

🔥 3. Use .gitignore to Exclude Unnecessary Files
Example .gitignore for Node.js projects:

node_modules/
.env
*.log

🔥 4. Use Aliases for Shortcuts
Speed up your workflow with aliases in ~/.gitconfig:

git config --global alias.co checkout
git config --global alias.cm "commit -m"
git config --global alias.st status

🔥 5. Never Use git reset --hard on Public Branches
It erases commits permanently. If you need to undo, use git revert.


🎯 Final Thoughts

Congratulations! 🎉 You now understand Git & GitHub better than 90% of beginners.

But remember—Git is a skill. The more you use it, the more it makes sense. Don’t be afraid to break things (as long as you know how to fix them 😉).

💡 Your Next Challenge:
Try using Git for all your projects for a week. No file copy-pasting. No “final_final_v3” folders. Just pure Git-powered efficiency.

Happy coding! 🚀👨‍💻

About the author

  • I am a Senior Software Engineer at BigBasket with over three years of experience in software development. Specializing in QA automation, CI/CD, and mobile automation, I am passionate about creating efficient workflows and sharing knowledge through blogs and articles.

    I actively contribute to the tech community through my work, open-source projects, and insightful content. Feel free to connect with me on GitHub or LinkedIn to explore my projects and contributions.

No comments yet. Be the first to comment.

More from this blog