🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now β†’
Menu

Categories

10 Git Commands That Will Save You Hours Every Week

10 Git Commands That Will Save You Hours Every Week

Most developers use only a fraction of Git's capabilities. These 10 commands will dramatically improve your daily Git workflow and save you hours of work every week.

1. git stash β€” Save Work in Progress

# Stash current changes
git stash save "WIP: fixing login bug"

# List all stashes
git stash list

# Apply most recent stash
git stash pop

# Apply specific stash
git stash apply stash@{2}

# Stash including untracked files
git stash -u

2. git log --graph --oneline β€” Visual History

# Beautiful branch visualization
git log --graph --oneline --all --decorate

# Create an alias for convenience
git config --global alias.lg "log --graph --oneline --all --decorate"

# Now just use:
git lg

3. git diff --staged β€” Review Before Committing

# See what you are about to commit
git diff --staged

# Diff with word-level changes
git diff --staged --word-diff

# Diff specific file
git diff --staged path/to/file.py

4. git commit --amend β€” Fix Last Commit

# Fix the last commit message
git commit --amend -m "Correct commit message"

# Add forgotten files to last commit
git add forgotten-file.js
git commit --amend --no-edit

5. git cherry-pick β€” Copy Specific Commits

# Apply a specific commit to current branch
git cherry-pick abc1234

# Cherry-pick without committing
git cherry-pick --no-commit abc1234

# Cherry-pick a range
git cherry-pick abc1234..def5678

6. git bisect β€” Find Bug-Introducing Commits

# Start bisecting
git bisect start
git bisect bad          # Current version is broken
git bisect good v1.0    # v1.0 was working

# Git checks out a middle commit - test it
# Then mark it:
git bisect good  # or  git bisect bad

# Repeat until Git identifies the exact commit
git bisect reset  # When done

7. git reflog β€” Recover Lost Work

# Show all recent HEAD movements
git reflog

# Recover a "deleted" branch
git checkout -b recovered-branch HEAD@{5}

# Undo a bad reset
git reset --hard HEAD@{2}

8. git rebase -i β€” Clean Up History

# Interactive rebase last 5 commits
git rebase -i HEAD~5

# In the editor, you can:
# pick   - keep commit as is
# squash - merge with previous commit
# reword - change commit message
# drop   - remove commit entirely
# edit   - pause to amend commit

9. git worktree β€” Multiple Working Directories

# Create a new working directory for a branch
git worktree add ../hotfix-branch hotfix/urgent-fix

# Work in both directories simultaneously
# No need to stash or switch branches!

# List worktrees
git worktree list

# Remove when done
git worktree remove ../hotfix-branch

10. git blame β€” Track Line History

# See who changed each line
git blame path/to/file.py

# Blame with date format
git blame -e path/to/file.py

# Blame specific line range
git blame -L 10,20 path/to/file.py

# Ignore whitespace changes
git blame -w path/to/file.py

Bonus: Useful Git Aliases

# Add these to your ~/.gitconfig
git config --global alias.st "status -sb"
git config --global alias.co "checkout"
git config --global alias.br "branch -v"
git config --global alias.unstage "reset HEAD --"
git config --global alias.last "log -1 HEAD --stat"
git config --global alias.visual "log --graph --oneline --all"

Learn More

Share this article:
Mikkel Sorensen
About the Author

Mikkel Sorensen

UX/UI Design, Java Development, User-Centered Application Design, Technical Documentation

Mikkel SΓΈrensen is a UX/UI-focused software developer with a strong background in Java-based application development.

He works at the intersection of user experience design and software engineering, creating applications that are both technically robust and user-centered. His experience includes interface design, inter...

UX Design UI Design Java Applications User Experience Engineering Accessibility Basics

Stay Updated

Subscribe to our newsletter for the latest tutorials, tips, and exclusive offers.