Essential Git Commands: The Daily Workflow

Essential Git Commands: The Daily Workflow
1. Starting a Project: init vs. clone
git init: Use this when you are creating a "New" project from scratch on your own laptop. It creates the hidden.gitfolder (the magic database).git clone: Use this when the project already exists on GitHub. It downloads the entire history, every branch, and every commit.
Pro Tip: Always use the SSH link instead of HTTPS when cloning. It's more secure and prevents you from having to type your password every 5 minutes (Module 273).
2. Tracking Changes: The "Add & Commit" Rhythm
Git doesn't automatically "See" your changes. You must tell it what is important.
A. git status (The "Mental Map")
Run this command constantly. It tells you exactly what Git is thinking.
- Red: Files you changed but Git hasn't saved yet.
- Green: Files you've "Staged" for the next snapshot.
B. git add . (The Staging Area)
Think of this as "Packing the suitcase." You are choosing which files are ready to be saved.
C. git commit -m "..." (The Snapshot)
This is "Closing the suitcase" and labeling it. Rule of Thumb: Commit Early and Often. Small commits are easy to fix; massive 1,000-line commits are a nightmare for your team to review.
3. Syncing with the World: push and pull
git push: Sends your local commits to the server (GitHub).git pull: Downloads your teammates' changes and merges them into your code.
Danger Zone: Never force-push (--force) to a shared branch unless you are an expert. You can delete your coworkers' work from existence!
4. History: git log and git diff
git log --oneline --graph: Shows you a beautiful, simplified map of who did what and when.git diff: Shows you the exact lines of code that changed before you commit them. Use this as a "Self-Review" to ensure you didn't leave anyconsole.logor "TODO" comments in your code.
Frequently Asked Questions
What is a 'HEAD'? Head is just a "Pointer." It tells you which commit you are currently looking at. When you move between branches, the "HEAD" moves with you.
How do I undo a commit?
If you haven't pushed yet, you can use git reset --soft HEAD~1. This "Undoes" the commit but keeps your code changes, allowing you to fix a typo and commit again.
Key Takeaway
Git mastery isn't about memorizing commands; it's about understanding the Lifecycle. By mastering the rhythm of status -> add -> commit -> push, you provide your team with a clear, professional history that makes your codebase stable and your career indestructible.
Read next: The Git Lifecycle: Understanding the Staging Area →
Part of the GitHub Mastery Course — engineering the daily.
