Beyond git add, commit, and push — the Git commands that actually save you when things go wrong: undoing commits, resolving conflicts, stashing, rebasing, and cleaning up history.
In this guide
Undo the last commit but keep changes staged: git reset --soft HEAD~1. Undo the last commit and unstage changes (files are modified, not staged): git reset HEAD~1. Undo the last commit and discard all changes (destructive): git reset --hard HEAD~1. If you already pushed, use git revert HEAD instead — this creates a new commit that undoes the change without rewriting history that others may have pulled.
Save uncommitted changes temporarily: git stash. Give it a name: git stash push -m "WIP: auth feature". List stashes: git stash list. Apply the most recent stash: git stash pop (applies and removes). Apply without removing: git stash apply. Apply a specific stash: git stash apply stash@{2}. Stash is your safety net when you need to quickly switch branches without committing half-finished work.
When a merge conflict occurs, run git status to see conflicted files. Open each file — conflict markers look like: <<<<<<< HEAD (your version) ======= (incoming version) >>>>>>> branch-name. Edit the file to the correct final state, removing the markers. Then: git add <file> and git commit. Use git mergetool to open a visual diff tool. VS Code has built-in conflict resolution UI that makes this much faster.
git merge feature creates a merge commit that preserves the full branch history. git rebase main replays your commits on top of main, creating a linear history. For shared branches (main, develop), always merge — never rebase public history. For personal feature branches before opening a PR, rebase to keep the history clean: git checkout feature && git rebase main. Never force-push to branches other people are working on.
git blame <file> shows the last commit that modified each line — commit hash, author, date, and the line itself. In VS Code, install the GitLens extension for inline blame annotations. Use git log -S "search term" to find which commit added or removed a specific string — useful for tracking down when a bug was introduced. git log --oneline --graph shows a visual branch history in the terminal.
Delete a local branch: git branch -d feature-name (safe, fails if unmerged). Force delete: git branch -D feature-name. Delete a remote branch: git push origin --delete feature-name. Remove references to deleted remote branches: git remote prune origin. Remove untracked files: git clean -fd (dry run first: git clean -fdn). Run git gc periodically to compress the repository and clean up loose objects.
Need Help?
Our engineering team handles implementations like this every week. Get a free scoping call — we will tell you exactly what it takes and what it costs.
Book a free callCompetitive Intelligence
Efficiency Modeling
© 2026 NexWorldTech — Built for Global Dominance.