git push

Sharing and Updating

Update remote refs along with associated objects


The 'git push' command uploads local repository content to a remote repository. It transfers commits and branch updates (and tags, when you ask for them with --tags or --follow-tags) from your local repo to a remote, making your changes available to others. Push is how you share your work - after committing locally, you push to synchronize with team members. By default (push.default=simple), git push only updates the current branch's upstream branch, which must exist and have the same name, and only if it is a fast-forward update (meaning the remote branch is an ancestor of your local branch).

Synopsis

git push [--all | --mirror | --tags] [--follow-tags] [--atomic] [-n | --dry-run] [-f | --force] [-d | --delete] [--prune] [-q | --quiet] [-v | --verbose] [-u | --set-upstream] [-o <string>] [--force-with-lease[=<refname>[:<expect>]] [--force-if-includes]] [--no-verify] [<repository> [<refspec>...]]
[ ] optional| or<arg> placeholder... repeatable--flag option

Options

Click any option to expand

Beginner (7)

The remote repository to push to. When no remote is specified, Git uses the current branch's configured remote (its upstream), falling back to 'origin'. The repository can be a URL or the name of a remote.

When neededNames the target remote explicitly; otherwise the upstream remote is used

Example

git push origin main

For every branch that is up to date or successfully pushed, add upstream (tracking) reference. This allows you to use 'git push' and 'git pull' without arguments for this branch in the future.

RecommendedSet once on a new branch; plain push and pull then just work

Example

git push -u origin feature-branch

Push all branches to the remote: every branch under refs/heads/ goes to the same-named branch on the remote. Since Git 2.41 it is also spelled --branches. Tags are not included, and it cannot be combined with other refspecs.

When neededPushes every local branch, including experiments you meant to keep private

Example

git push --all origin

Push all refs under refs/tags, in addition to refspecs on the command line. All local tags will be pushed to the remote.

When neededPushes every local tag, including stray or lightweight ones

Example

git push --tags origin

Do everything except actually send the updates. Shows what would be pushed without making any changes to the remote.

When neededPreviews what would be pushed; the pre-push hook still runs

Example

git push --dry-run origin main

Run verbosely. Provides additional output about what is being pushed and the progress of the operation.

When neededMore detail when debugging a push

Example

git push -v origin main

Suppress all output, including the listing of updated refs, unless an error occurs. Progress is not reported.

When neededFor scripts; output only on errors

Example

git push -q origin main

Intermediate (6)

All listed refs are deleted from the remote repository. This is the same as prefixing all refs with a colon (e.g., :branch-name).

When neededRemoves a remote branch after merging; cannot be undone from the remote

Example

git push --delete origin feature-old

Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. This flag disables these checks and allows non-fast-forward updates. This can cause the remote repository to lose commits; use with care.

Not recommendedOverwrites the remote blindly — use --force-with-lease instead

Example

git push --force origin feature-branch

A safer alternative to --force. This option allows force push but first checks that the remote ref hasn't been updated by someone else since you last fetched. If the remote has changed, the push is rejected, preventing you from accidentally overwriting someone else's work. The check compares against your remote-tracking branch, so a fetch (even a background one) without integrating resets it; pair with --force-if-includes.

RecommendedThe safe way to push rewritten history; refuses if the remote moved

Example

git push --force-with-lease origin feature-branch

Transmit the given string to the server, which passes them to the pre-receive and post-receive hooks. Can be specified multiple times to send multiple options. Useful for triggering CI/CD behaviors or passing metadata.

When neededSends server-specific options (e.g. CI hints) your host understands

Example

git push -o ci.skip origin main

Remove remote branches that don't have a local counterpart. Only applies to refs matched by a wildcard refspec (or --all): with a plain 'git push --prune origin' nothing is deleted. Deletes remote branches irreversibly, so preview with --dry-run.

Not recommendedDeletes remote branches missing locally; one stale clone can wipe teammates’ work

Example

git push --all --prune origin

Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed, locally updated refs will be force updated, and deleted refs will be removed. In effect, it force-pushes every ref and deletes remote refs that don't exist locally.

Not recommendedForce-updates and deletes every ref on the remote; only for backups or migrations

Example

git push --mirror origin

Advanced (11)

Skip the pre-push hook. By default, git push runs the pre-push hook if it exists. This option bypasses that local check (server-side hooks still run). Use sparingly, as pre-push hooks typically enforce important checks like running tests.

Not recommendedSkips your pre-push checks; only when a broken hook blocks a push

Example

git push --no-verify origin main

GPG-sign the push request to update refs on the receiving side. This allows the server to verify the identity of the pusher. Requires GPG keys to be configured, and the server must support signed pushes - otherwise the push fails ('the receiving end does not support --signed push'). Can also be set to 'true', 'false', or 'if-asked' (sign only if the server supports it).

When neededGPG-signs the push; fails unless the server supports signed pushes

Example

git push --signed origin main

Use an atomic transaction on the remote side when available. Either all refs are updated, or on error, no refs are updated. If the server does not support atomic pushes, the push will fail. Useful when pushing multiple interdependent branches.

When neededAll-or-nothing when pushing several related refs together

Example

git push --atomic origin main develop

Push all the refs that would be pushed without this option, and also push annotated tags in refs/tags that are missing from the remote but are pointing at commit-ish that are reachable from the refs being pushed. This can be set as default with push.followTags config.

RecommendedPushes annotated release tags on pushed commits, skipping lightweight ones

Example

git push --follow-tags origin main

This option is an alternative to the <repository> argument. If both are specified, the command-line argument takes priority. Can be used in scripts or configurations to explicitly specify the target repository.

When neededRarely needed; same as giving the repository argument

Example

git push --repo=origin main

Optimize the transfer by sending a 'thin' pack, which records objects in deltified form based on objects not included in the pack to reduce network transfer. This is the default behavior.

When neededAlready the default; you never need to type it

Example

git push --thin origin main

Disable the 'thin' pack optimization. This sends a complete pack without relying on objects that may exist on the receiving side. Can be useful for debugging transfer issues.

When neededOnly for troubleshooting pack transfers

Example

git push --no-thin origin main

Force progress status to be displayed on the standard error stream, even if the stream is not connected to a terminal. Useful in scripts where you still want to see push progress.

When neededForces progress output in logs or CI where stderr is not a terminal

Example

git push --progress origin main

Force an update only if the tip of the remote-tracking ref has been integrated locally. This is a safer force push that ensures you have actually integrated any new remote commits into your work before overwriting them. It only has an effect together with --force-with-lease (without an explicit expected value).

RecommendedAdd to --force-with-lease so a background fetch can't bypass the lease

Example

git push --force-with-lease --force-if-includes origin feature

Produce machine-readable output. The output status line for each ref will be tab-separated and sent to stdout instead of stderr. Useful for scripts that need to parse push results.

When neededMachine-readable results for scripts

Example

git push --porcelain origin main

Control how submodules are handled during push. Values: 'check' (fail if submodule commits aren't pushed), 'on-demand' (push submodule commits if needed), 'only' (only push submodules), 'no' (don't recurse).

When neededMakes sure submodule commits are pushed first

Example

git push --recurse-submodules=on-demand origin main

Choosing the Right Option

Force Push Safety Ladder

When you need to overwrite remote history, choose the safest option that works for your situation

CommandRisk LevelChecks RemoteWhen It FailsUse Case
git pushSafe✓ Fast-forward onlyIf remote has new commitsNormal daily workflow
git push --force-with-lease --force-if-includesSafest force✓ Remote tip in local historyIf you haven't integrated remote changesAfter rebase when others may have pushed
git push --force-with-leaseSafer force✓ Remote unchanged since fetchIf remote changed since last fetchAfter rebase on personal branch
git push --forceDangerous✗ Overwrites blindlyNever (unless rejected by server)Only when you're certain, or solo branch

What Gets Pushed

Control the scope of what you're sending to the remote

CommandPushesTags IncludedTypical Use
git push origin mainSingle branch✗Push specific branch
git push -u origin branchSingle branch + sets tracking✗First push of new branch
git push --allAll branches✗Sync all local branches
git push --tagsTags only (no branches)✓ All tagsPush version tags
git push --follow-tagsCurrent branch✓ Reachable annotated onlyPush with relevant release tags
git push --mirrorEverything✓ AllExact remote clone (deletes remote-only refs)

Output & Feedback

Control verbosity and output format based on your needs

CommandOutput LevelShows ProgressMachine ParseableBest For
git pushStandardIn terminal only✗Normal interactive use
git push --verboseDetailed✓✗Debugging push issues
git push --quietErrors only✗✗Scripts, CI pipelines
git push --progressStandard + forced progress✓ Always✗Scripts that need progress in logs
git push --porcelainStructured✗✓ Tab-separatedParsing push results in scripts

Safety & Verification

Pre-push checks and verification options

CommandRuns HooksVerifiesCreates CommitWhen to Use
git push✓ pre-pushRemote acceptsN/ANormal workflow
git push --dry-run✓ pre-pushWhat would happen✗ Preview onlyBefore important pushes
git push --atomic✓All refs or noneAll-or-nothingPushing multiple branches together
git push --no-verify✗ Skips local pre-push (server hooks still run)Remote acceptsN/AEmergency when hooks block you
git push --signed✓GPG signatureCryptographically signedHigh-security repos, proving identity

Remote & Branch Management

Options for managing remote refs and branch relationships

CommandActionAffects RemoteUse Case
git push -u origin branchPush + set upstreamAdds branchFirst push, sets up tracking
git push origin --delete branchDelete remote branchRemoves branchClean up merged branches
git push --pruneDelete remote branches you deleted locally (needs --all or a wildcard refspec)Removes branchesSync deletions to remote
git push --repo=<url>Push to specific remoteTarget remotePush to alternate remote URL

Workflow Examples

1
git remote add origin https://github.com/user/repo.git

Add the remote repository URL

2
git push -u origin main

Push main branch and set it to track origin/main

1
git status

Verify you're on the correct branch and have commits to push

2
git push

Push to the tracked upstream branch

1
git checkout feature

Switch to your feature branch

2
git rebase main

Rebase onto main (rewrites commit history)

3
git push --force-with-lease

Safely force push - fails if someone else pushed

1
git checkout -b feature/new-login

Create and switch to new branch

2
git add . && git commit -m "Add new login"

Make your changes and commit

3
git push -u origin feature/new-login

Push and set upstream tracking

1
git push origin --delete feature/old-branch

Delete the remote branch

2
git branch -d feature/old-branch

Delete the local branch too

1
git push --all origin

Push all branches under refs/heads/

2
git push --tags origin

Optionally also push all tags

Troubleshooting

! [rejected] main -> main (fetch first) / (non-fast-forward)

Cause: The remote branch has commits that your local branch doesn't have. Someone else pushed changes, or you rebased/amended commits that were already pushed.

Pull the remote changes first with 'git pull --rebase' or 'git pull --no-rebase', resolve any conflicts, then push again. Only force (preferably '--force-with-lease') if you're certain no one else is using the branch.

git pull --rebase && git push

git@github.com: Permission denied (publickey)

Cause: SSH authentication failed: no key is loaded, or your public key isn't added to your account. (Missing write access shows a different 'Permission to ... denied' error.)

Check that your SSH key is added to your GitHub/GitLab account. Verify with 'ssh -T git@github.com'. For HTTPS, ensure you're using the correct credentials.

ssh -T git@github.com

fatal: No configured push destination

Cause: The repository has no remote configured at all. (If a remote exists but the branch has no upstream, you get 'The current branch ... has no upstream branch' instead.)

Add a remote with 'git remote add origin <url>', then push and set the upstream with 'git push -u origin <branch>'.

git push -u origin main

Your branch is behind 'origin/main'

Cause: The remote branch has newer commits than your local branch. You need to integrate those changes before pushing.

Fetch and merge or rebase the remote changes into your local branch before pushing.

git pull origin main && git push

refusing to update checked out branch

Cause: You're trying to push to a non-bare repository where that branch is currently checked out. This could cause the working directory to become inconsistent.

Push to a bare repository, or have the receiver check out a different branch first. This usually happens with personal server setups, not with GitHub/GitLab.

git config receive.denyCurrentBranch updateInstead

error: failed to push some refs to '<remote-url>'

Cause: Generic error that can have multiple causes: non-fast-forward updates, hook failures, or permission issues. Check the detailed error message above this line.

Read the full error output. Usually it's a non-fast-forward issue (pull first) or a pre-push hook failure (fix the issues the hook reports).

git pull --rebase && git push

pre-push hook failed

Cause: A pre-push hook (running tests, linting, etc.) found issues and blocked the push.

Fix the issues reported by the hook. Only bypass with '--no-verify' if absolutely necessary and you understand the consequences.

git push --no-verify

remote: Repository not found

Cause: The repository URL is incorrect, the repository was deleted, renamed, or you don't have access to it.

Verify the repository URL with 'git remote -v'. Check that the repository exists and you have access. Update the URL if needed.

git remote set-url origin https://github.com/user/correct-repo.git

Tips & Pitfalls

Best Practices

  • ✓Always pull before push: Run 'git pull' (or 'git fetch' followed by a merge or rebase) before pushing to ensure you have the latest remote changes and avoid rejected pushes.
  • ✓Use --force-with-lease instead of --force: If you must force push, --force-with-lease is safer because it fails if someone else pushed to the remote since your last fetch (add --force-if-includes for extra safety).
  • ✓Set upstream on first push: Use 'git push -u origin branch-name' when pushing a new branch to set up tracking. This lets you use plain 'git push' afterward.
  • ✓Never force push to shared branches: Force pushing to main, master, or develop can destroy other people's work. Use revert commits instead of rewriting history.
  • ✓Use branch protection rules: Configure your repository to prevent force pushes to important branches and require pull request reviews.
  • ✓Push frequently to backup your work: Regular pushes to feature branches serve as backups and let others see your progress.
  • ✓Verify before pushing: Use 'git push --dry-run' to see what would be pushed without actually pushing. Great for double-checking.
  • ✓Clean up remote branches: Delete merged feature branches with 'git push origin --delete branch-name' to keep the remote repository tidy.
  • ✓Use atomic pushes for related changes: When pushing multiple branches that depend on each other, use '--atomic' to ensure all succeed or none do.
  • ✓Sign important pushes: For security-critical repositories, use '--signed' to GPG-sign your push requests for verification (the server must support signed pushes, otherwise the push fails).

Common Mistakes

  • ✗Pushing without pulling first: If the remote has new commits, your push will be rejected. Always 'git pull' (or fetch, then merge/rebase) first to incorporate remote changes.
  • ✗Using --force on shared branches: Force pushing rewrites history and can destroy other people's work. Use --force-with-lease instead, or better yet, avoid force pushing to shared branches entirely.
  • ✗Forgetting to set upstream with -u: On first push of a new branch, use 'git push -u origin branch-name' to set up tracking. Otherwise you'll need to specify the remote and branch every time.
  • ✗Pushing to the wrong branch: Double-check your current branch with 'git branch' before pushing. Use explicit syntax like 'git push origin feature:feature' to be safe.
  • ✗Not understanding rejected pushes: 'non-fast-forward' errors mean the remote has commits you don't have locally. Pull and merge/rebase before pushing, don't just force push.

FAQ

A:

'git push' uploads your local commits to a remote repository, making your changes available to others. 'git pull' downloads commits from a remote and merges them into your local branch. Push sends data out; pull brings data in.

A:

You can't truly 'undo' a push since it's shared history. For safe reversal, use 'git revert HEAD' to create a new commit that undoes the changes, then push again. Avoid using 'git reset' + force push on shared branches as it rewrites history others may have pulled.

A:

The -u flag sets up a tracking relationship between your local branch and the remote branch. After using 'git push -u origin feature', you can simply use 'git push' and 'git pull' without specifying the remote and branch each time.

A:

Force push (--force) should only be used on branches where you're the only contributor, like personal feature branches after rebasing. Never force push to shared branches like main or develop. If you must, use --force-with-lease for safety.

A:

Use the refspec syntax: 'git push origin local-branch:remote-branch'. For example, 'git push origin feature:experiment' pushes your local 'feature' branch to a remote branch called 'experiment'.

A:

Usually because the remote has commits you don't have locally (non-fast-forward). Run 'git pull' to fetch and merge those changes, resolve any conflicts, then push again. Don't force push unless you're certain it's safe.

A:

Use 'git push --all origin' to push all local branches to the remote. Tags need a separate command because '--all' and '--tags' cannot be combined: 'git push --tags origin'.

A:

'--force' blindly overwrites the remote branch regardless of its state. '--force-with-lease' only overwrites if the remote hasn't changed since you last fetched - it fails if someone else pushed, protecting their work. Caveat: a fetch (even an IDE's background fetch) refreshes that check, so add --force-if-includes to also require that you've integrated what you fetched.

A:

Use 'git push origin --delete branch-name' or the shorthand 'git push origin :branch-name'. Both remove the branch from the remote repository.

A:

Plain 'git push' only works if the current branch has an upstream branch configured. For new branches, you need 'git push -u origin branch-name' first. Check with 'git branch -vv' to see tracking relationships.