name: git-push-remote description: Push the current branch to the remote repository with upstream tracking
Git Push Remote
Push the current branch to the remote repository, setting up tracking if needed.
In worktree workflows, run this skill from the ticket's dedicated worktree path.
Inputs
worktree_path(recommended): absolute path to the ticket worktreebranch(optional): branch name; if omitted, resolve from the worktree
Steps
Resolve working context:
If
worktree_pathis provided, prefer explicit-Ccommands:git -C "{worktree_path}" rev-parse --show-toplevel git -C "{worktree_path}" branch --show-currentIf
branchis not provided, resolve it from the same path.If branch resolves to empty (detached HEAD), stop and return an actionable error.
Confirm repository/worktree location:
- Always report the resolved top-level path used for push.
Check if upstream is set:
git -C "{worktree_path}" rev-parse --abbrev-ref --symbolic-full-name "@{upstream}" 2>/dev/nullPush to remote:
If no upstream is set (new branch):
git -C "{worktree_path}" push -u origin "{branch}"If upstream exists:
git -C "{worktree_path}" push origin "{branch}"Never rely on implicit current directory branch for pushes in multi-worktree workflows.
Error Handling
Push Rejected (Remote Has Changes)
If push is rejected because remote has new commits:
git -C "{worktree_path}" pull --rebase origin "{branch}"
git -C "{worktree_path}" push origin "{branch}"
If there are conflicts during rebase:
- Inform the user about the conflicts
- List the conflicting files
- Ask for guidance on resolution
No Commits to Push
If there are no commits to push, inform the user that the branch is up to date.
Authentication Issues
If authentication fails:
- Check if SSH key or token is configured
- Suggest running
gh auth loginfor GitHub - Ask user to verify their credentials
Verification
After pushing, verify the push succeeded:
git -C "{worktree_path}" log "origin/{branch}" -1 --oneline
Report the pushed commit hash and message to confirm success.
Also report the worktree path used for the push.