sync

git push

Uploads local commits from a branch to a remote repository, updating the remote-tracking references. Requires push permission on the remote.

git push [<remote> [<refspec>]]

Common flags

Flag Purpose
-u / --set-upstream Track the remote branch so future 'git push' works without args
--force-with-lease Safer force push that fails if the remote has new work
-f / --force Overwrite the remote branch (dangerous)
--tags Push tags along with commits
--delete <branch> Delete the named branch on the remote
--dry-run Show what would be pushed without actually sending

Examples

git push -u origin main

Push main and set upstream on first push

git push --force-with-lease

Push rewritten history safely after a rebase

git push origin --delete feature/old

Delete a stale remote branch

Gotcha

Prefer --force-with-lease over --force; plain --force will silently clobber teammates' commits on shared branches.

Related commands

← All Git commands · Git cheat sheet · Git rebase vs merge