How to Push a Git Worktree Branch to a Remote
Prepared and checked using AI. Sources are linked in the article.
To push a Git worktree branch to a remote, go to that worktree, commit the changes you want reviewed, and run git push -u origin <branch>. The -u flag sets the remote branch as the local branch’s upstream, so later pushes can usually be just git push. Replace origin with the remote you can write to, and confirm the branch name before publishing.
Check the worktree and remote
For example, suppose an agent worked in ../agent-auth on branch agent/auth. Run these commands from that worktree:
cd ../agent-auth
git branch --show-current
git status --short
git remote -v
A linked worktree has its own checked-out HEAD, index, and working files. Its directory name does not determine which branch a push will publish. git branch --show-current prints the branch name and prints nothing for a detached HEAD. If it does not show the branch you intend to share, resolve that before pushing.
git status --short shows staged, unstaged, and untracked changes. A push transfers commits, so inspect this output for agent edits that still need a commit. It is especially easy to overlook a newly created file when the rest of a task is already committed; see why agent worktrees can miss uncommitted changes.
git remote -v shows the configured remote names and URLs. Choose the remote that should hold the review branch. In a repository with a personal fork, that may be your fork rather than the upstream project. If no remote is listed, there is no named destination for git push -u origin …; configure the intended remote with your repository host’s URL before continuing.
If the changes you want reviewed are still uncommitted, stage the intended files and make a commit. For example:
git add src/auth.ts tests/auth.test.ts
git commit -m "Add auth flow"
git status --short
git add places selected file contents in the index for the next commit; naming paths makes the selection explicit. git commit -m records the staged changes with the supplied message. If the agent edits a file again after staging it, stage that file again before committing. Keep unrelated local files out of the review branch unless they are part of the task.
Publish the branch and set its upstream
Once the branch and remote are correct, push the named branch:
git push -u origin agent/auth
Here, the first name is the remote and the second is the local branch. With the usual same-name mapping, the remote receives agent/auth; -u records origin/agent/auth as its upstream when the push succeeds or the remote branch is already up to date. This is a branch operation: there is no separate worktree push command.
If you want to check the proposed update before sending it, use:
git push --dry-run origin agent/auth
--dry-run reports the push without sending the update. It does not publish the branch or set the upstream. Run the real command afterward. Prefer the explicit branch name over a broad option such as --all when several agents have local branches in the same repository.
You can also push the branch while your shell is in another worktree by naming it explicitly: git push -u origin agent/auth. Working inside the agent’s worktree makes it easier to inspect its files and commits first, but the push source is the named branch. If the branch is checked out elsewhere, find the worktree that owns it before making further edits.
Verify what later pushes will do
After the successful push, check the tracking relationship:
git branch -vv
git status -sb
Look for the current branch paired with origin/agent/auth. The upstream matters beyond pushing: it is also the branch Git uses for an argument-free git pull, and status can show whether the local and upstream branches have diverged. It is not the pull request’s base branch. A review might compare agent/auth against main, while agent/auth tracks its own remote counterpart.
For the usual same-name setup, the next cycle is:
git add src/auth.ts tests/auth.test.ts
git commit -m "Address review feedback"
git push
Git’s default push.default=simple pushes the current branch to a same-name branch on the chosen remote. Repository or user configuration can change what an argument-free push selects. If you work with multiple remotes or custom push mappings, use git push origin refs/heads/agent/auth:refs/heads/agent/auth to specify both the source and destination branch. git branch -vv shows upstream tracking; it does not show configured push mappings.
If the branch was already pushed without -u, run git push -u origin agent/auth now. Git can set the upstream even when the remote branch is already up to date. If tracking points to the wrong existing remote branch, set it explicitly and verify again:
git branch --set-upstream-to=origin/agent/auth
git branch -vv
Use that correction only when origin/agent/auth is the branch you intend to pull from and push to. Changing the upstream does not move commits or change the remote branch’s contents.
Make the branch available for review
A successful push makes the branch available on the chosen remote; it does not itself open a review request. On GitHub, select the pushed branch as the compare branch and the intended merge target as the base branch. Check that the review shows the intended commits and files before requesting review. If the work is unfinished, GitHub also offers a draft pull request.
Later commits pushed to the same head branch can update that pull request. This gives reviewers one place to follow revisions while the agent’s worktree remains available for fixes. When the review is complete, use the repository’s normal merge process; merging parallel agent branches covers how to bring separate tasks together.
Handle common push failures
No upstream is configured
A plain git push can fail on a new branch because Git does not know which remote branch to track. Run git push -u origin agent/auth, substituting your branch and remote. If that succeeds, verify the tracking name with git branch -vv before relying on a plain push.
The worktree has a detached HEAD
If git branch --show-current prints nothing, create a named branch at the current commit before the first push. git switch -c creates and switches to a new branch:
git switch -c agent/auth
git push -u origin agent/auth
Choose a name that is not already used by another local branch. Avoid resetting an existing branch just to make a detached worktree pushable.
The remote rejects the update
A remote branch may already contain commits absent from the local branch. A normal push protects that branch by rejecting a non-fast-forward update. Inspect the remote branch and integrate the work you need before retrying. Do not treat git push --force as a routine fix: it can replace remote commits. If your team intentionally rewrites a review branch, coordinate that change with its reviewers and check the remote state first.
A different rejection may come from a remote-side rule or hook. Read the push error and resolve the stated rule; setting an upstream does not bypass server policy.
The branch went to the wrong remote
Check git remote -v, then push explicitly to the intended destination. For example, if fork is your writable remote:
git push -u fork agent/auth
git branch -vv
This sets the branch’s upstream to the fork’s same-name branch after a successful push when that remote has the usual same-name mapping. Confirm the review request uses that fork branch as its head. A branch published to one remote is not automatically published to every other remote.
Optional default for new branches
If you regularly create same-name review branches, push.autoSetupRemote=true makes a default push set upstream tracking when the branch has none. It applies with push.default values simple, upstream, and current:
git config --global push.autoSetupRemote true
With that setting, a first plain git push can establish the upstream in a suitable repository. Explicit git push -u <remote> <branch> is still useful when you need to choose among remotes or make a one-off destination clear. The setting is a convenience for your Git configuration, not a property of the worktree.
Where Parallel Code fits
Parallel Code is our free, open-source desktop app for macOS and Linux. It runs AI coding agents in parallel, each isolated in its own Git worktree, and provides a diff-first review surface. When an agent’s branch is ready for others to review, use the Git push and upstream steps above from that worktree.
Frequently asked questions
Do I push the worktree or its branch?
Push the branch. A worktree is the working directory where that branch is checked out; the remote receives branch commits, not a copy of the directory or its uncommitted files.
Is git push -u origin agent/auth needed every time?
No. Use it for the first successful push when you want to establish origin/agent/auth as upstream. For later same-name pushes, git push usually works, subject to your Git push configuration.
What if I already pushed the branch without -u?
Run git push -u origin agent/auth again; an up-to-date branch can still gain upstream tracking. Check git branch -vv afterward to confirm the remote and branch name.
Does setting an upstream choose the pull request’s base?
No. Upstream tracking identifies the remote counterpart of your local branch for Git operations such as pull and push. Choose the pull request’s base, such as main, separately in your hosting service.