In the modern DevOps landscape, Git is no longer just a "nice-to-have" skill; it is the backbone of professional software engineering. Whether you are building an ASP.NET Core multi-tenant application or managing complex Oracle migrations, understanding the nuances of Git can save hours of debugging and prevent catastrophic data loss.
This article provides an end-to-end roadmap of Git commands, categorized by mastery levels.
1. The Core Fundamentals: The Local Workflow
Before pushing to a remote server, every developer must master the local "Three-Tree" architecture: the Working Directory, the Staging Area (Index), and the Commit History.
Essential Commands
git init: Initialize a new Git repository in your project root.
git status: Displays the state of the working directory and staging area.
git add <file>: Moves changes to the staging area. Use git add . to stage everything.
git commit -m "feat: implement user authentication": Records the snapshot.
2. Branching & Team Collaboration
Working directly on the main branch is a recipe for disaster. Professional .NET teams use Feature Branching or GitFlow.
Commands for Collaboration
git checkout -b feature/payment-gateway: Creates and switches to a new branch.
git switch <branch>: The modern, safer way to switch between branches.
git merge <branch>: Combines changes into your current branch.
git remote add origin <url>: Connects your local repo to GitHub, Azure DevOps, or GitLab.
git push -u origin <branch>: Uploads your branch and sets the upstream tracking.
git pull: Fetches and merges updates from the remote in one command.
3. The "Undo" Palette: Fixing Mistakes
As developers, we often make mistakes—committing to the wrong branch or accidentally deleting a file. Git provides a safety net for almost every scenario.
Discarding Local Changes: git restore <file>
Unstaging a File: git restore --staged <file>
Fixing the Last Commit: git commit --amend
Soft Reset: git reset --soft HEAD~1
Hard Reset: git reset --hard HEAD~1
4. Intermediate Mastery: Stashing & Cleaning
Sometimes you aren't ready to commit, but you need to switch branches to fix a critical bug in production.
git stash: "Freezes" your current work and clears the working directory.
git stash pop: "Unfreezes" your work and brings it back to your branch.
git clean -fd: Removes all untracked files and directories. This is great for cleaning up /bin and /obj folders that weren't ignored.
5. Advanced Architect: History Manipulation
This is where you separate the juniors from the seniors. Clean history is vital for enterprise projects like AJK_CFRS or CitizenInfo.
Rebase vs. Merge
While merge creates a "merge commit," rebase rewrites history to make it a straight line.
Interactive Rebase (The "Squash")
Cherry-Picking
6. The Wizard Level: Deep Recovery & Debugging
When things go horribly wrong, these "plumbing" commands are your best friend.
git reflog: The "Log of Logs." It shows every single move the Git HEAD has made. Even if you deleted a branch, you can find the commit hash here and restore it.
git bisect: A binary search tool to find the exact commit that introduced a bug.
git bisect start
git bisect bad (current version is broken)
git bisect good <hash> (this old version worked)
Git will guide you through the commits to find the culprit.
Pro-Tip: The .NET Developer's .gitignore
In the world of Visual Studio, your repository should only contain source code—never binaries or user settings. Ensure your .gitignore includes:
Conclusion
Mastering Git is an iterative process. Start with the basics of staging and committing, then move to branching. Once comfortable, explore Interactive Rebasing to keep your project history clean.