gh-stack icon indicating copy to clipboard operation
gh-stack copied to clipboard

Set branch upstream

Open dbushong opened this issue 4 months ago • 4 comments

Many tools expect to be able to find the associated upstream for a given branch; gh stack currently manages that internally.

When one does gh stack init some-branch, then at such time as gh stack actually pushes the branch to origin, it should do the equivalent of git push --set-upstream origin some-branch in order to create the association.

This lets the user push future changes with just git push (and check for updates with git pull), as well as letting git status show relative differences.

dbushong avatar Jul 27 '26 21:07 dbushong

Ran into this today as well. gh stack submit pushed the branch and created the PR, but VS Code still showed the branch as unpublished because it had no upstream.

The workaround was:

branch=$(git branch --show-current)
git branch --set-upstream-to="origin/$branch" "$branch"

To avoid this in the future, I've added an upstream check after gh stack submit to my agent workflows so this doesn't get missed. That works, but ideally every user and agent shouldn't need gh-stack-specific cleanup after publishing a branch. It would be great if gh-stack set the upstream itself.

farmerpaul avatar Aug 13 '26 14:08 farmerpaul

At least as an option if not the default. I find this very cumbersome as well.

jrochkind avatar Oct 08 '26 16:10 jrochkind

Workaround suggested by a LLM:

# ~/.zshrc
function gh() {
  if [[ "$1" == "stack" && "$2" == "submit" ]]; then
    command gh "$@"
    local exit_code=$?
    if [[ $exit_code -eq 0 ]]; then
      # Automatically set upstream tracking for any local branch that has a remote match on origin
      for branch in $(git branch --format='%(refname:short)'); do
        if git rev-parse --verify "origin/$branch" >/dev/null 2>&1; then
             git branch --set-upstream-to="origin/$branch" "$branch" 2>/dev/null
        fi
      done
      echo "🔗 Upstream tracking automatically linked for stack branches."
    fi
    return $exit_code
  else
    command gh "$@"
  fi
}

eexit avatar Nov 10 '26 15:11 eexit

+1 . This drives me crazy 😄

Please operate as normal git would, graphite had no problems here ❤️

alanrynne-dandy avatar Nov 24 '26 11:11 alanrynne-dandy