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
git pull
Fetches from the remote and integrates the changes into the current branch, effectively 'git fetch' followed by 'git merge' (or rebase). Updates your working tree with upstream commits.
git fetch
Downloads objects and refs from a remote without modifying your working tree or current branch. Safest way to see what's new upstream before integrating.
git remote
Manages the set of named remote repositories your local repo tracks, such as origin or upstream. Lets you add, rename, remove, or inspect remote URLs.