Working with remote repositories¶
Note
This page assumes you are using one of the supported Git forges. These are:
- GitHub
- GitLab (v0.9.0)
If you're using a different service, you can still use git-spice, but some features may not be available.
See:
Submitting change requests¶
Info
git-spice uses the term Change Request to refer to submitted branches. These corespond to Pull Requests on GitHub, and to Merge Requests on GitLab.
When your local changes are ready, use the following commands to submit your changes upstream:
- gs branch submit (or gs bs) submits the current branch
- gs downstack submit (or gs dss) submits the current branch and all branches below it
- gs upstack submit (or gs uss) submits the current branch and all branches above it
- gs stack submit (or gs ss) submits all branches in the stack
Branch submission is an idempotent operation: change requests will be created for branches that don't already have them, and updated for branches that do.
For new change requests, these commands will prompt you for CR information. For example:
$ gs branch submit
Title: branch submit: Fix directory+ref conflict
Body: Press [e] to open nvim or [enter/tab] to skip
Draft: [y/N]
INF Created #261: https://github.com/abhinav/git-spice/pull/261
Important
Be aware that for stacks with multiple branches, you must have write access to the repository so that you can push branches to it. See Limitations for more information.
Navigation comments¶
Change Requests created by git-spice will include a navigation comment at the top with a visual representation of the stack, and the position of the current branch in it.
This behavior may be changed with the
Stack history in navigation comments
Non-interactive submission¶
Use the --fill
flag (or -c
since
$ gs stack submit --fill
INF Created #123: https://github.com/abhinav/git-spice/pull/123
INF Created #125: https://github.com/abhinav/git-spice/pull/125
Additionally, with
$ gs branch submit \
--title "Fix a bug" \
--body "This fixes a very bad bug."
INF Created #123: https://github.com/abhinav/git-spice/pull/123
Setting draft status non-interactively
Change requests may be marked as draft or ready for review
non-interactively with the --draft
and --no-draft
flags.
By default, the submit commands will leave
the draft state of existing PRs unchanged.
If the --draft
or --no-draft
flags are provided,
the draft state of all PRs will be set accordingly.
Force pushing¶
$ gs branch submit --force
By default, git-spice will refuse to push to branches
if the operation could result in data loss.
To override these safety checks
and push to a branch anyway, use the --force
flag.
Update existing CRs only¶
All submit commands support the --update-only
flag.
If provided, the submission will update existing CRs in a stack,
but not create new ones.
This is most convenient with
Example workflow
Suppose we're starting with a stack:
main -> bird (#1) -> fish (#2) -> goat
bird
and fish
have already been submitted, goat
is in-progress.
# While working in goat, make a minor fixup to bird.
[goat] $ gs commit create -m 'bird: preen a little'
# Pull that change into bird
[goat] $ gs branch checkout bird
[bird] $ git restore --source $(gs top -n) -- bird.go
[bird] $ gs commit create -a -m 'preen a little'
INF fish: restacked on bird
INF goat: restacked on fish
# Update fish and bird in one command without submitting goat
[bird] $ gs stack submit --update-only
INF bird: Updated #1
INF goat: Updated #2
INF goat: Skipping unsubmitted branch: --update-only
Tip
The above example makes use of the -n
/--dry-run
flag
of the stack navigation commands.
With this flag, the command prints the hash of the target branch
without checking it out.
Syncing with upstream¶
To sync with the upstream repository,
use
$ gs repo sync
INF main: pulled 3 new commit(s)
INF feat1: #123 was merged
INF feat1: deleted (was 9f1c9af)
This will update the trunk branch (e.g. main
)
with the latest changes from the upstream repository,
and delete any local branches whose PRs have been merged.
Handling closed Change Requests¶
When running
If you prefer not to be prompted about closed CRs, you can set the configuration option to ignore them:
$ git config spice.repoSync.closedChanges ignore
For more details, see the configuration reference.
Importing open CRs¶
You can import an existing open CR into git-spice by checking it out locally, tracking the branch with git-spice, and re-submitting it.
For example:
# Check out the PR locally
$ gh pr checkout 359
# Track it with git-spice
$ gs branch track
# Re-submit it
$ gs branch submit
INF comment-recovery: Found existing CR #359
INF CR #359 is up-to-date: https://github.com/abhinav/git-spice/pull/359
# Check out the MR locally
$ glab mr checkout 8
# Track it with git-spice
$ gs branch track
# Re-submit it
$ gs branch submit
INF reticulating-splines: Found existing CR !8
INF CR !8 is up-to-date: https://gitlab.com/abg/test-repo/-/merge_requests/8
Important
For this to work, the following MUST all be true:
- The CR is pushed to a branch in the upstream repository
- The local branch name exactly matches the upstream branch name
This will work even for CRs that were not created by git-spice, or authored by someone else, as long as the above conditions are met.
In
$ gs branch submit
INF comment-recovery: Found existing CR #359
INF comment-recovery: Found existing navigation comment: ...
Importing stacks of CRs¶
If you have a stack of related CRs to import,
check out all the branches locally
and use
# Check out the PRs locally
$ gh pr checkout 359
$ gh pr checkout 360
$ gh pr checkout 361
# Track the entire downstack
$ gs downstack track
See also