How to Push to Main From a Git Worktree

Nov 11, 2026

I've been using git worktrees a lot lately. They let you have several branches checked out at once, each in its own folder, which is handy when more than one thing is in flight. (In my case, often more than one AI agent working on the same repo.)

The catch shows up when you're done and want your work on main. The obvious move doesn't work:

$ git checkout main
fatal: 'main' is already checked out at '/path/to/repo'

A branch can only be checked out in one worktree at a time, and main is checked out in the original folder.

Why Pushing Your Branch to Main Gets Rejected

The next thing you might try is pushing your branch straight onto the remote main:

$ git push origin feature:main
 ! [rejected]        feature -> main (non-fast-forward)
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.

That works only if nobody else has touched main since you branched. If they have, it's rejected. And git's advice, check out the branch, is the one thing you can't do here. Don't reach for --force either. It would throw away the commits that moved main.

Merge Main Into Your Branch, Then Push

You don't need to check out main. You need your branch to contain it:

git fetch origin
git merge origin/main
git push origin HEAD:main

fetch grabs the latest main from the remote. merge folds it into your branch, right there in your worktree, and if there are conflicts you resolve them here. Now your branch is main plus your work, so pushing it to main is a fast-forward:

$ git push origin HEAD:main
   3d0728d..aaf88de  HEAD -> main

Then confirm the SHA that's actually on the remote:

git fetch origin
git rev-parse --short origin/main

If that SHA matches your HEAD, you're on main. The original folder still has its old main checked out, so run a git pull there next time you use it.

Thanks for reading! I'd love to hear your thoughts - if you have something you want to share feel free to leave a comment or shoot me an email.

Comments

Leave a Comment