Set branch upstream
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.
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.
At least as an option if not the default. I find this very cumbersome as well.
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
}
+1 . This drives me crazy 😄
Please operate as normal git would, graphite had no problems here ❤️