Git Push
Last updated
git push uploads the commits on your local branch to its remote counterpart (like GitHub). Once a branch has an upstream set, a plain git push is enough; the first push of a new branch uses -u to create the remote branch and set up tracking so future pushes and pulls need no arguments.
Try these in the terminal playground - a real shell in your browser, nothing to install.
Syntax
| Command | What it does |
|---|---|
git push | Push the current branch to its upstream |
git push -u origin feature | Push a new branch and set upstream |
git push origin main | Push to a specific remote and branch |
git push --tags | Push all local tags |
git push --force-with-lease | Force push safely after a rebase |
Common cases
| Goal | Command |
|---|---|
| Push a brand-new branch | git push -u origin feature |
| Push after the upstream is set | git push |
| Push a single tag | git push origin v1.0.0 |
| Delete a remote branch | git push origin --delete feature |
Git push FAQ
How do I push a new branch to the remote?
Run
git push -u origin <branch>. The -u (short for --set-upstream) creates the branch on the remote and links your local branch to it, so afterwards a plain git push and git pull work without arguments. The remote branch doesn't exist until this first push.Why does git push say 'no upstream branch'?
Your local branch isn't linked to a remote branch yet. Push it with
git push -u origin <branch> to create the remote branch and set the upstream. After that, git push alone knows where to send commits.How do I push tags?
Tags aren't pushed by default. Push a single tag with
git push origin <tagname>, or push all of them at once with git push --tags. This is a common gotcha - a tag you created locally won't appear on the remote until you push it explicitly.How do I force push safely?
After rewriting history (a rebase or amend), use
git push --force-with-lease rather than --force. It only overwrites the remote if no one else has pushed since your last fetch, protecting teammates' work. See the git force push page for the full explanation.Can I practice this online?
Yes. Open the terminal playground to run
git push in a real shell in your browser - nothing to install. Coddy's free interactive Git course also covers working with remotes step by step.