π Introduction
Git is the heart of modern development workflows. While most developers are familiar with git add, git commit, and git push, there's a whole world of advanced Git commands that can save time, prevent disasters, and help you debug like a pro. Letβs level up!
π Why Go Beyond the Basics?
Understanding advanced Git operations helps:
Clean up messy histories
Fix mistakes without panic
Navigate and debug efficiently
Collaborate more effectively
βοΈ Advanced Git Commands
git reflogβ Your Time Machine
bash
Copy
Edit
git reflog
Shows a log of where your HEAD and branch references have been. Useful for recovering lost commits!git cherry-pickβ Pick and Choose Commits
bash
Copy
Edit
git cherry-pick <commit-hash>
Apply specific commits from one branch into another. Great for patching bugs without merging entire branches.git bisectβ Debugging Power Tool
bash
Copy
Edit
git bisect start
git bisect bad
git bisect good <commit>
Use binary search to find the exact commit that introduced a bug. Super handy in large codebases.git stashβ But Make It Fancy
bash
Copy
Edit
git stash save "WIP: fixing navbar"
git stash list
git stash pop
Temporarily shelve your changes. You can even apply them selectively using stash@{n}.git rebase -iβ Rewrite History Like a Boss
bash
Copy
Edit
git rebase -i HEAD~3
Interactive rebasing lets you squash, edit, or reorder commits. Use it to clean up your commit history before a PR.git resetβ Know Your Levels
bash
Copy
Edit
git reset --soft HEAD~1
git reset --mixed HEAD~1
git reset --hard HEAD~1
Roll back commits with precision. Soft keeps your changes, hard doesnβt.git cleanβ Remove the Untracked
bash
Copy
Edit
git clean -fd
Clears untracked files and directories. Be carefulβitβs permanent!git blameβ Find Who Changed What
bash
Copy
Edit
git blame <file>
Annotates each line in the file with the commit and author. Useful for tracking bugs or changes.git logβ But Prettier
bash
Copy
Edit
git log --oneline --graph --decorate --all
See a visual, colorful graph of your commit history. Great for understanding merges and branches.
π Pro Tips
Use aliases for long commands (git config --global alias.lg "log --oneline --graph --decorate")
Combine git stash with git checkout to switch branches safely
Before a pull request, use git rebase -i to squash commits
π Conclusion
These commands will give you superpowers in managing Git repositories. Donβt fear the terminal β embrace it. The more fluent you get with Git, the smoother your dev life will be.
π Further Reading
π Pro Git Book
https://git-scm.com/book/en/v2
π Git Cheatsheet by GitHub Education
https://education.github.com/git-cheat-sheet-education.pdf
π§  Learn Git Branching (Interactive Visual Tool)
https://learngitbranching.js.org
    
Top comments (0)