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.
This is the ultimate, end-to-end master reference for Git. It covers every phase of the development lifecycle—from the first line of code to advanced repository recovery.
Phase 1: Setup and Configuration
Before you touch code, you must configure your environment and identify yourself.
git config --global user.name "Your Name": Sets your name for commits.
git config --global user.email "[email protected]": Sets your email.
git config --global core.editor "code --wait": Sets your default text editor (e.g., VS Code).
git config --global alias.<shortcut> <command>: Creates custom shortcuts (e.g., git config --global alias.st status).
git config --list: Displays all active configurations.
Phase 2: Starting and Acquiring Projects
git init: Initializes a new local Git repository.
git clone <url>: Downloads an existing repository and its entire history.
git clone --depth 1 <url>: Performs a "shallow clone" (latest commit only) to save space.
git remote add origin <url>: Links your local repo to a remote server (like GitHub or Azure DevOps).
Phase 3: The Daily Workflow (Staging & Committing)
This is the heart of Git. You move work from the "Working Directory" to the "Index" (Staging), then to the "Repository."
git status: Shows modified files and what is currently staged.
git add <file>: Stages a specific file.
git add .: Stages all changes in the current directory.
git add -p: Interactively stage parts of a file (hunks).
git commit -m "Message": Records the staged snapshot permanently.
git commit -a -m "Message": Stages all tracked files and commits in one step.
git commit --amend: Adds changes to the previous commit or fixes the message.
Phase 4: Branching and Merging
In professional projects like your EsahulatMultiTenant or AJK_CFRS, branching is used to keep the main code safe.
git branch: Lists all local branches.
git branch -a: Lists all local and remote branches.
git switch -c <name>: Creates and switches to a new branch (modern version of checkout -b).
git switch <name>: Switches to an existing branch.
git merge <branch>: Merges the specified branch into your current branch.
git branch -d <name>: Deletes a branch that has been merged.
git branch -D <name>: Force-deletes a branch (even if unmerged).
Phase 5: Remote Collaboration
git fetch: Downloads all history from the remote but doesn't change your files.
git pull: Fetches and immediately merges remote changes into your branch.
git push origin <branch>: Uploads your local commits to the remote.
git remote -v: Lists all connected remote repositories.
git push origin --delete <branch>: Deletes a branch on the remote server.
Phase 6: Inspection and Comparison
git log --oneline --graph --all: Visualizes the branch tree and history.
git diff: Shows changes in the working directory vs. the index.
git diff --staged: Shows changes in the index vs. the last commit.
git diff <branch1> <branch2>: Compares two branches.
git blame <file>: Shows who changed every line of a file and when.
git show <commit>: Displays the detailed changes of a specific commit.
Phase 7: Undoing and "Time Travel"
git restore <file>: Discards local changes in a file (reverts to last commit).
git restore --staged <file>: Unstages a file but keeps the code changes.
git reset --soft HEAD~1: Undoes the last commit but keeps changes staged.
git reset --hard HEAD~1: Deletes the last commit and all changes (destructive).
git revert <hash>: Creates a new commit that is the exact opposite of a past commit (safe for shared history).
git clean -fd: Removes all untracked files and directories.
Phase 8: The "Waiting Room" (Stashing)
git stash: Temporarily shelves uncommitted changes.
git stash list: Shows all stashed items.
git stash pop: Applies the latest stash and removes it from the list.
git stash apply: Applies the stash but keeps it in the list.
git stash drop: Deletes a specific stash.
Phase 9: Advanced History & Maintenance
git rebase <branch>: Re-writes your branch's history to start from the tip of another branch.
git rebase -i HEAD~n: Interactive Rebase. Use this to "Squash" (combine), "Reword," or "Fixup" the last n commits.
git cherry-pick <hash>: Copies a single commit from another branch to yours.
git reflog: The master log of all HEAD movements. Use this to find "lost" commits.
git bisect start/bad/good: Binary search tool to find which commit introduced a bug.
git tag -a v1.0 -m "Release": Creates a permanent marker for a specific version.
git gc: Runs garbage collection to optimize the database.
git fsck: Checks the integrity of the Git file system.
Pro Tip for .NET Developers
Since you work with Visual Studio 2022, remember that while the GUI is great, the CLI (command line) allows you to perform interactive rebasing and reflog recovery, which the GUI often cannot do.
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.
Did you find this guide helpful? For my next article, would you like me to focus on setting up a CI/CD pipeline for ASP.NET Core using Git actions?