10 Git Commands You’ll Wish You Knew Earlier
- Get link
- X
- Other Apps
10 Git Commands You’ll Wish You Knew Earlier
Git can feel intimidating when you’re starting out. Most of us stick to the basics: git add
, git commit
, and git push
. That works... until it doesn’t. These 10 commands can save you when things get tricky.
1. git reflog
Ever made a mistake so bad you wished you could turn back time? git reflog
is your time machine.
- Use case: Recover a commit after a bad reset or deleted branch.
git reflog
2. git cherry-pick
Need a specific commit from another branch? Use git cherry-pick
without merging the entire branch.
- Use case: Apply a bug fix from one branch to another.
git cherry-pick <commit-hash>
3. git bisect
Debugging a bug that suddenly appeared? Let Git do the detective work with git bisect
.
- Use case: Identify the exact commit introducing a bug.
git bisect start git bisect bad git bisect good <commit-hash>
4. git stash pop
Switch branches without losing your work using git stash
, then restore it with git stash pop
.
- Use case: Temporarily save uncommitted changes to focus on a critical bug fix.
git stash pop
5. git reset --soft
Want to rework a commit? Move it back to the staging area without losing changes.
- Use case: Re-edit a recent commit.
git reset --soft HEAD~1
6. git blame
Identify who modified each line in a file with git blame
.
- Use case: Understand why a specific change was made.
git blame <file>
7. git log --oneline --graph
View your project’s history in a simple, visual format.
- Use case: Track branching and merging histories.
git log --oneline --graph --all
8. git clean -f
Clean up untracked files cluttering your working directory.
- Use case: Remove conflicting untracked files when pulling updates.
git clean -f
9. git rebase -i
Clean up messy commit histories with interactive rebasing.
- Use case: Squash or edit commits before merging.
git rebase -i HEAD~<number-of-commits>
10. git diff --staged
Review staged changes before committing with git diff --staged
.
- Use case: Double-check staged modifications.
git diff --staged
Conclusion
Mastering these commands can save you from common Git headaches and make your workflow smoother. Which of these commands will you try first?
- Get link
- X
- Other Apps
Comments
Post a Comment