Git how-tos
Step-by-step guides for working across Git repositories, branches and worktrees. See what to check before you push or clean up.
Find unpushed commits across all your Git repositories
Ask Git what is unpushed in one repository, then on every branch, then across a whole folder of repositories with one loop. And see where the loop stops.
How to clean up old Git worktrees and merged branches
List your Git worktrees, remove the ones you’ve finished with, and check which branches are merged before you delete them.
How to stop accidental Git pushes to production
Protect main and other deployment branches with a local pre-push hook, branch protection on your Git host, and a quick check of your push destination.
How to delete merged and stale Git branches safely
Find local branches whose remote copy is gone, check which are merged, delete those, and look twice at the rest before you force anything.
Fix: The current branch has no upstream branch
Why Git refuses a plain push on a new branch, how git push -u fixes it, how to check what a branch tracks, and how to stop the error for good.
How to move a Git worktree to a new folder
Move a linked Git worktree with its branch and local edits intact, repair it after a manual move, and handle worktrees with submodules.
How to see what you are about to push in Git
Read the commits, the files and the diff that a push would send, branch by branch, with plain Git before you run it.
Push a Git branch without checking it out
Push a finished branch by name while you keep editing another. Check the remote destination and confirm your checkout stayed put.
“Your branch is ahead of origin by N commits”: what it means and what to do
Git says your branch is ahead of origin. That means you have commits its last copy of the server branch doesn't. See which ones, then push them or keep them local on purpose.
Command line, Git client or scripts for many repositories
Each way of keeping many Git repositories in check, what it does well, and what it leaves to you.
Find uncommitted changes across all your Git repositories
Ask Git what is changed but not committed in one repository, then in a whole folder of repositories with one loop, worktrees included. And see where the loop stops.
Fix “failed to push some refs” in Git
If your Git push was rejected with “fetch first” or “non-fast-forward”, fetch the target branch, bring in its commits, then push again.
How to fix “protected branch hook declined” in Git
Find out why your Git host rejected the push and send your local commits for review.
“Your branch and origin have diverged”: how to fix it safely
Git says your branch and origin have diverged. See what is on each side, choose rebase or merge, and force-push only the safe way.
Git stash vs. WIP commit vs. a new branch
Halfway through a change and need to switch tasks? Save a named stash, leave a work-in-progress commit, or open the urgent fix in a separate worktree.
Committed to the wrong branch? Move your unpushed commits
Save your commits on a new Git branch, then reset the original branch to its last published commit.
Recover lost commits with git reflog
Find a commit after a reset, rebase, or branch deletion. Save it to a new branch and keep your current checkout in place.
How to tidy unpushed commits in Git before you push
Fold a wip commit into the one it belongs to, fix a message, add a forgotten file, all on local commits only, so the history you push reads clean.
Force push safely with --force-with-lease
Why a plain force push can erase a teammate's commit, what --force-with-lease actually checks, where a background fetch defeats it, and when to skip force pushing altogether.
How to push one commit from a Git branch
Copy one ready fix onto a branch based on the remote destination, then check exactly what your push will send.
Update many Git repositories with git pull --ff-only
Why --ff-only is the calm way to pull, what it refuses, and one loop that brings a whole folder of repositories up to date without ever creating a merge commit.
How to push a single tag in Git
Check which commit a local tag points to, preview the push, and confirm that the same tag landed on the remote.
How to undo the last commit in Git before you push it
Take the newest commit back out of your history and keep your work, as staged changes or plain edits, as long as it has not been pushed.
Fix: src refspec does not match any
Why Git says src refspec does not match any on a push, how to check the branch name and the first commit, and how to confirm the remote branch.
How to undo a Git commit you already pushed
Use git revert to undo a change on a shared branch and keep the history your teammates already have.
How to save commits from a detached HEAD
Spot a detached HEAD, name its current tip with a branch, and check the commits are safe before you switch away.
Fix “branch is already checked out” in a Git worktree
Find the folder that has the branch open, work there or branch off, and check for unsaved work before you free the original.
Or let your Mac keep watch
push& (Pushand) is a Mac menu bar app that does this for you. It counts the unpushed commits across your repositories and worktrees, and pushes a ready branch in one click.