Description
Pushes refs to a remote over SSH, smart HTTP, or the file:// transport. With no refspecs, grit pushes the current branch using the same remote-selection rules as Git (branch.<name>.pushRemote, remote.pushDefault, branch.<name>.remote, then origin) and applies remote.<name>.push refspecs when configured.
When you pass refspecs, the optional <remote> may be a configured remote name, a URL, an scp-style host:path, or a filesystem path (including relative paths such as ../bare), the same as grit fetch and grit pull. A lone positional that is not one of those is still a refspec pushed to the default remote. With several positionals, the first must name a remote, URL, or path; anything else fails with unknown remote. A push to a URL or filesystem path (such as C:\t\remote.git or ../bare) creates and updates no remote-tracking refs, as with Git; only a configured remote's refs/remotes/<name>/… refs follow the push.
A remote written as <owner>/<project> and followed by at least one refspec is a repository on the default grit host: grit push me/app main pushes to https://code.gitbutler.com/me/app.git, or to that path under $GRIT_DEFAULT_HOST when it is set. A configured remote with the same name takes precedence. After a push like this from a repository with no remotes yet, grit saves the URL as origin, so later grit push and grit fetch go there. A lone <owner>/<project> argument is still a refspec, so grit push topic/x pushes a branch to the default remote.
Incremental SSH and HTTP pushes stop exploring advertised commit history once the new commit frontier is exhausted. A one-commit push does not need to walk every advertised branch and tag back to its root. Annotated tags targeting blobs or trees may be advertised alongside commit refs without preventing a push.
On the remote, receive.denyNonFastForwards, receive.denyDeletes, and receive.denyCurrentBranch are enforced for every transport, including local-path remotes (not only grit receive-pack over HTTP).
From a shallow clone, grit announces each shallow boundary in the push command stream (like Git) and sends only the reachable commits. When the remote does not already have the history below those boundaries, the remote must set receive.shallowUpdate=true or the update is refused with shallow update not allowed; see grit receive-pack.
A push to a local path or file:// URL runs the remote repository's pre-receive, update, post-receive and post-update hooks just as grit receive-pack and Git do: the pushed objects wait in a quarantine that pre-receive can read, a non-zero pre-receive refuses every update (pre-receive hook declined) and keeps the objects out of the repository, a non-zero update refuses its own ref (hook declined), and post-receive and post-update run after the refs are written. Hook output is reported like any remote's messages. --dry-run runs none of these hooks, as with Git.
Explicit refspecs follow Git push rules: any revision on the left (HEAD, tags, branches), optional + for force, :dst to delete, and a bare branch name DWIMs to the matching local ref (then through configured push refspecs when present). Wildcard refspecs such as refs/heads/*:refs/heads/* or refs/remotes/origin/*:refs/heads/* expand against local refs the same way as remote.<name>.push entries in config.
--all pushes every local branch (refs/heads/*:refs/heads/*), including branches the remote does not have yet. --mirror pushes all refs under refs/*, forces updates, and deletes remote refs under refs/ with no local counterpart (it implies --prune and force). --prune deletes stale refs only in the destination namespace of a wildcard or matching refspec (for example with --all or refs/heads/*:refs/heads/*, including refs/heads/*:refs/tmp/*). Pushing a single branch with --prune does not remove other remote branches. --all, --mirror, and --delete cannot be combined with each other or with positional refspecs.
--dry-run negotiates with the remote and reports what would change without updating refs or sending objects.
With --tags, pushes every local tag under refs/tags/.
With --delete, every positional after the remote names a remote branch or tag to delete (short names map like Git), and nothing is pushed. All of them are deleted in one push, with one result per ref. They must be plain ref names: a src:dst refspec next to --delete is an error and nothing is sent, as is --delete with no ref. To publish one ref and delete another, run two pushes or use a :dst refspec without --delete (grit push origin HEAD:release :old). --delete cannot be combined with --tags.
--force-with-lease updates a remote ref only when it still matches the local remote-tracking ref mapped from the push destination (or when the ref is absent if there is no tracking ref). Use --force-with-lease=<rev> when pushing exactly one ref to compare against a specific commit. --force overwrites the remote ref unconditionally. The two flags cannot be combined.
A branch you share (branch.<name>.shared is true) is pushed with --force-with-lease without your asking: your head of it is yours alone, so replacing it after an amend or rebase is safe, as long as the server's head is still the one you last fetched. After the push, grit fetches the other members' heads: one that diverged from yours but goes together with it without losing anything is combined with your branch here and pushed again (combined in --json); one that needs a decision is reported with its options, and the push exits 3.
-u / --set-upstream writes branch.<name>.remote and branch.<name>.merge for each successfully pushed branch (skipped with --dry-run).
--atomic requires every ref update in the push to succeed or none are applied, including when a remote update hook rejects one ref. Over SSH, git://, and smart HTTP, the server must advertise the atomic capability. If it does not, grit fails before sending ref updates or objects; it never falls back to a non-atomic push. This capability check also applies to --dry-run.
-o / --push-option sends server-side push options (for example ci.skip), which the remote's pre-receive and post-receive hooks see as GIT_PUSH_OPTION_COUNT and GIT_PUSH_OPTION_<n>. The remote must accept them: a server advertises the push-options capability, and a local-path or file:// remote must set receive.advertisePushOptions. Otherwise the push fails before anything is sent, --dry-run included.
--follow-tags pushes annotated tags that point to commits reachable from the refs being pushed (lightweight tags and unreachable annotated tags are skipped). The config key push.followTags enables the same behavior by default.
In human output, messages the remote sends while it processes the push (hook output, CI links, policy text) are shown on stderr as remote: … lines, including when stderr is not a terminal. -q / --quiet hides them and the human summary, so a successful push prints nothing; a rejected push is still reported and exits 1. With --json or --markdown, the same lines appear in remote_messages (omitted when empty).
On a TTY, grit draws live progress on stderr while it builds and streams the pack (enumerating objects, then writing/compressing), then prints a short time/data summary after the ref results when anything was sent — the same style as grit fetch and grit pull. --json and --markdown omit the live lines and summary; phase timings are not exported in JSON today.
Before anything is sent, grit runs the repository's pre-push hook (see grit hooks) once the remote's current refs are known, on every transport and with --dry-run too. The hook gets the remote name (or the URL, for an unnamed remote) and the push URL as arguments, and one line per ref update on stdin, <local ref> <local oid> <remote ref> <remote oid>, in Git's format: (delete) and a zero object id for deletions, a zero remote object id for new refs, and no line for refs that are up to date or already rejected. If the hook exits non-zero, the push stops, the remote is left untouched and grit exits 1. The hook's stdout is sent to stderr so --json and --markdown output stays clean. --no-verify skips the hook.
Large pushes
When a smart-HTTP server advertises a resumable push endpoint (the pushBundle capability, as grit serve does) and the pack to send is larger than 16 MiB, grit writes the pack as a bundle and uploads it with the TUS resumable-upload protocol instead of one long request, then asks the server to apply the ref updates. The result is reported like any other push. A dropped connection is retried from the server's offset, and an interrupted push keeps its bundle and upload in .git/grit/push-bundles/: run the same grit push again and it skips building the pack and sends only the rest.
↻ Resuming push bundle upload at 12.0 MiB of 29.6 MiB (41%) example.com/demo/push/97d00bc69d6359be08d3a13753f95d2a
✓ push bundle 29.6 MiB in 3.4s · 5.20 MiB/s · resumed at 12.0 MiB
Set push.bundleThreshold (bytes, with optional k, m or g) to change the size at which this starts.
When a push is interrupted (SIGINT, SIGTERM, or SIGHUP, including Ctrl+C from a terminal), grit cancels the in-progress transfer, removes any partial receive quarantine or tmp_pack_* file it was writing on the remote, and exits 130 without updating remote refs. Stale temp files from a hard kill (SIGKILL) are removed later by grit gc once they are older than gc.pruneExpire, the same way git gc prunes abandoned quarantine directories.
For GitHub over HTTPS, if a push fails because you aren't signed in, grit offers to run grit auth and then tries again.
Options
| Option | Description |
|---|---|
<remote> |
Remote name, URL, or filesystem path (optional; defaults from branch / config). |
<refspec>... |
Push refspecs (feature, HEAD:refs/heads/x, +main:main, :gone, …). |
-t, --tags |
Push all local tags instead of the current branch. |
--delete |
Delete the remote refs named by the positionals instead of pushing (plain names only). |
--all |
Push every local branch (refs/heads/*:refs/heads/*). |
--mirror |
Mirror all refs under refs/ (force + prune remote-only refs). |
--prune |
Delete stale refs in the wildcard refspec destination namespace (not on single-ref pushes). |
--dry-run |
Contact the remote but do not update refs or send objects. |
-f, --force |
Overwrite remote refs when the update is not a fast-forward. |
--force-with-lease |
Push only if the remote ref matches the local remote-tracking ref (or is absent when there is no tracking ref). |
--force-with-lease=<rev> |
Same check against <rev> (exactly one ref must be pushed). |
-u, --set-upstream |
Set upstream config for pushed branches. |
--atomic |
All ref updates succeed or none are applied; fails before sending updates if the server does not support atomic pushes. |
-o, --push-option |
Server-side push option (repeatable; the remote must accept push options). |
--follow-tags |
Push annotated tags reachable from the commits being pushed. |
-q, --quiet |
Suppress remote messages and the human summary of a successful push. |
--no-verify |
Skip the pre-push hook. |
--remote |
Hidden alias for the remote name (prefer the positional <remote>). |
JSON output
Schema: v1
Pass --json for stable, scripting-friendly output:
| Field | Type | Meaning |
|---|---|---|
remote |
string | Remote that was pushed to: its name, or the URL given with any user:password@ removed. Human and Markdown output show the same value. |
kind |
string | branch, tags, delete, or refspecs. |
branch |
string or null | Short branch name when kind is branch, or the deleted branch’s short name when kind is delete and exactly one branch is deleted. Omitted for tag and other explicit refspec pushes (kind: refspecs). |
dry_run |
boolean | true when --dry-run was used (no refs or objects written). |
results |
array | Per-ref outcomes; each object has ref, status (ok, up_to_date, or rejected), optional reason (stale for a failed lease or a ref another push moved meanwhile, already_exists when another push created the new ref first, tag_exists when the remote already has that tag and the push did not use --force, remote_ref_missing when --delete targets a ref absent on the remote), optional deleted (true when the ref was removed), old_oid, new_oid, src, and forced. |
rejected |
boolean | true if any ref was rejected (exit status is also 1). |
upstream_set |
array of strings | Branch short names whose upstream config was written (-u only; omitted when empty). |
origin_added |
string | URL saved as origin after an <owner>/<project> push from a repository with no remotes (omitted otherwise). |
remote_messages |
array of strings | Hook and diagnostic text from the remote (same lines as remote: … on stderr in human mode; omitted when empty). |
shared |
array | For each shared branch pushed: branch, combined (members whose heads were combined into yours and pushed again), head (your head after combining) and heads, the other members' heads fetched right after the push, each with user, tip, relation to your branch (same, ahead, behind, diverged or unknown), and for a head that diverged from yours divergence: scenario (a stable code such as amended_both_conflicting; see Divergence scenarios), summary, needs_decision, base, changes (each commit's change, subject, and what you and them did to it), conflicts and also. Omitted when no shared branch was pushed. |
pushed_to_integrated |
array | Branches this push made again after a share of them was integrated, bringing integrated commits: nobody shares them now (see After integrating). Each has branch, scenario (pushed_to_integrated), summary, by, at, into, target_branch, pull, url, integrated and new (how many of its commits were integrated, and how many are new) and options (rebase, rename, reshare, each with id, label, loses and command). Omitted when empty. |
When the pre-push hook fails, the push exits 1 with {"error":"hook pre-push failed with exit status 1"} on stdout and nothing is sent.
Markdown output
Pass --markdown for agent-friendly output.
Schema: v1
Markdown uses headings, bullet lists, and fenced blocks; pipe characters inside table cells are escaped. See the JSON output section for the stable field contract.
Exit status
| Code | Meaning |
|---|---|
0 |
Success (success). |
1 |
Command failed, a ref was rejected, or the pre-push hook exited non-zero (failure). |
2 |
Invalid flags or arguments (usage). |
3 |
Pushed, but a shared branch's heads diverged in a way someone has to decide about, or the push made a branch again that was shared and integrated (pushed_to_integrated) (needs_decision). |
128 |
Could not reach or read the remote: missing repository, DNS or connection failure, HTTP error status (remote_unreadable). |
See Exit codes for shared rules and structured --json kind values.