Most developers waste hours on Git because they rely on basic commands like git commit -m "fix" when faster tools exist. Advanced workflows require precision - below are commands that solve real problems without bloating history or slowing down CI pipelines.
Fix Mistakes Without History Pollution
Edit the last commit without creating a new one using git commit --amend. This is ideal for fixing typos or adding forgotten files before pushing. If you've already pushed, add --force-with-lease to update the remote branch safely.
git add forgotten_file.js
git commit --amend --no-edit
git push origin main --force-with-lease
Cherry-Pick Changes Across Branches
Move specific commits between branches with git cherry-pick. This avoids merging entire feature branches when only a subset of changes is needed. Resolve conflicts interactively by adding -x to preserve the original commit message context.

git checkout stable
git cherry-pick abc1234 -x
Rebase to Clean Commit History
Use git rebase -i HEAD~5 to squash messy commits into logical chunks before PRs. This creates a linear history that’s easier to review - but never rebase published commits as it breaks others’ workflows.

git rebase -i HEAD~5
# Mark commits with 'squash' in the editor
Show Only Your Changes in a Repo
Filter Git logs by author to debug ownership issues with git log --author="Your Name". Combine with --since and --until to narrow timeframes. This is invaluable when troubleshooting environment-specific bugs.
Never miss a story
Tools, tutorials and AI deep-dives - straight to your inbox, every week.
git log --author="Jane Doe" --since="2024-01-01" --until="2024-03-01"
Find Deleted Files Instantly
Recover accidentally deleted files with git fsck --lost-found. This lists dangling blobs containing all unreferenced content. Pipe to git show to inspect before recovery - faster than searching through commit history manually.
git fsck --lost-found
git show 0d3a7d...
Stop using git add -u for staged file management. It adds deletions by default, which often includes files you meant to remove from the repo permanently.
Real Tradeoffs
While these commands improve efficiency, they introduce risks. The rebase and cherry-pick workflows become dangerous if used on shared branches. Always communicate before rewriting history in collaborative repos.
Test these commands on feature branches first. Git’s power comes from understanding when automation helps and when it obscures intent - the difference between debugging in minutes and fighting history for hours.
Git Tips That Save Hours: 5 Hidden Tricks Most Skip
Frequently Asked Questions
- What does git force-with-lease do
- Overrides remote changes safely by verifying the current branch hasn't diverged. Use it instead of --force to avoid overwriting others' work
- How to squash Git commits
- Use git rebase -i with 'squash' in the editor to merge adjacent commits
- Can cherry-pick create conflicts
- Yes - apply changes from git diff manually first with --no-commit to resolve them before finalizing the pick