From claude-commands
Ensures proper Git remote branch tracking after PR creation to fix 'no remote' and 'no upstream' status issues. Guides -u flag pushes, upstream setup, and auto-config.
npx claudepluginhub joshuarweaver/cascade-code-general-misc-2 --plugin jleechanorg-claude-commandsThis skill uses the workspace's default tool permissions.
**Purpose**: Ensure proper remote branch tracking after creating PRs to avoid "no remote" and "no upstream" status issues.
Provides best practices, GitHub CLI commands, and bash script for creating PRs with upstream tracking and maintaining workflows. Useful for PR creation, git tracking fixes, and standardization.
Guides Git branch management and GitHub PR workflows using main-branch development, modern git switch/restore commands, and MCP tools for creating, listing, and updating PRs.
Creates GitHub Pull Requests using GitHub CLI: detects existing PRs for branches, pushes changes, generates titles/bodies from commits. Handles monorepos/submodules. Use for /create-pr or PR/review requests.
Share bugs, ideas, or general feedback.
Purpose: Ensure proper remote branch tracking after creating PRs to avoid "no remote" and "no upstream" status issues.
After creating a PR, the branch status may show:
Local: feature-branch (no remote) | Remote: no upstream
This happens when:
-u flagHEAD:branch-name instead of -u origin branch-name-u Flag (Recommended)When creating new branch and pushing:
git checkout -b feature-branch
git add .
git commit -m "Feature implementation"
git push -u origin feature-branch # โ Sets tracking automatically
When pushing existing branch:
git push -u origin HEAD # โ Pushes current branch and sets tracking
If you already pushed without -u:
# Check current tracking status
git branch -vv
# Set upstream for current branch
git branch --set-upstream-to=origin/feature-branch feature-branch
# Verify tracking is set
git branch -vv
Make all pushes set tracking by default:
git config --global push.autoSetupRemote true
Now any git push will automatically set tracking!
# Create feature branch from main
git checkout main
git pull origin main
git checkout -b feature/new-feature
# Make changes
git add .
git commit -m "Implement new feature"
# Push with tracking (ALWAYS use -u)
git push -u origin feature/new-feature
# After push with -u
gh pr create --title "Add new feature" --body "Description"
# Check branch tracking
git branch -vv
# Should show:
# * feature/new-feature abc1234 [origin/feature/new-feature] Commit message
# ^^^ Tracking info shown
# Show all branches with tracking info
git branch -vv
# Show remote branches
git branch -r
# Show all branches (local + remote)
git branch -a
# Option 1: Set tracking to existing remote branch
git branch --set-upstream-to=origin/$(git branch --show-current)
# Option 2: Push with -u to set tracking
git push -u origin HEAD
# Option 3: Enable auto-setup (one-time config)
git config --global push.autoSetupRemote true
# Fetch latest remote branch info
git fetch origin
# Prune deleted remote branches
git fetch --prune
git remote prune origin
Correct format after proper setup:
[Local: feature-branch | Remote: origin/feature-branch | PR: 2048 https://...]
Incorrect format (missing tracking):
[Local: feature-branch (no remote) | Remote: no upstream | PR: N/A]
#!/bin/bash
# create-pr.sh - Create branch, commit, push with tracking, and create PR
BRANCH_NAME="${1:-feature/$(date +%s)}"
PR_TITLE="$2"
PR_BODY="$3"
# Create and switch to new branch
git checkout -b "$BRANCH_NAME"
# Make changes (assumes already staged)
git commit -m "$PR_TITLE"
# Push with tracking
git push -u origin "$BRANCH_NAME"
# Create PR
gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base main
# Verify tracking
echo ""
echo "Branch tracking status:"
git branch -vv | grep "^\*"
Usage:
./create-pr.sh feature/add-validation "Add validation" "Implements input validation"
# โ WRONG - Doesn't set tracking
git push origin HEAD:feature-branch
# โ
CORRECT - Sets tracking
git push -u origin feature-branch
# or
git push -u origin HEAD
# โ WRONG - No tracking
git push origin feature-branch
# โ
CORRECT - Sets tracking
git push -u origin feature-branch
# โ WRONG ORDER
gh pr create ... # Fails - branch doesn't exist remotely yet
git push origin feature-branch
# โ
CORRECT ORDER
git push -u origin feature-branch # Push with tracking first
gh pr create ... # Then create PR
Cause: Branch not tracking any remote branch
Fix:
git branch --set-upstream-to=origin/$(git branch --show-current)
# or
git push -u origin HEAD
Cause: Same as "no remote" - missing tracking configuration
Fix: Same as above
Cause: Trying to push with -u but remote branch exists
Fix:
# If you own the remote branch
git push -u origin HEAD
# If someone else created it
git branch --set-upstream-to=origin/existing-branch
git pull # Merge remote changes
Cause: Remote branch deleted or never existed
Fix:
# Fetch latest remote info
git fetch origin
# Check if branch exists remotely
git branch -r | grep your-branch
# If doesn't exist, push with -u
git push -u origin your-branch
| Command | Purpose |
|---|---|
git push -u origin HEAD | Push and set tracking |
git branch -vv | Show tracking status |
git branch --set-upstream-to=origin/branch | Set tracking manually |
git config push.autoSetupRemote true | Auto-setup tracking (global) |
git fetch --prune | Update remote refs, remove deleted |
git remote -v | Show remote URLs |
# 1. Create branch
git checkout -b feature/my-feature
# 2. Make changes and commit
git add .
git commit -m "Implement feature"
# 3. Push with tracking (CRITICAL)
git push -u origin feature/my-feature
# 4. Create PR
gh pr create --title "Add feature" --body "Description"
# 5. Verify tracking
git branch -vv
# Expected output:
# * feature/my-feature abc1234 [origin/feature/my-feature] Implement feature
Use git aliases for common workflows:
git config --global alias.pushup '!git push -u origin HEAD'
git config --global alias.track '!git branch --set-upstream-to=origin/$(git branch --show-current)'
Enable auto-setup to never worry about -u:
git config --global push.autoSetupRemote true
Check tracking before PR:
git branch -vv | grep "^\*" | grep -q "\[origin/" || echo "โ ๏ธ No tracking set!"
Include tracking in git status:
git status -sb # Shows branch and tracking info
Last Updated: 2025-11-17 Applies To: Git 2.0+ Related: PR workflow, branch management, remote tracking