git push
git
Usage
git push [-u] [--force-with-lease] <remote> <branch>Sends your commits to a remote; --force overwrites the remote branch and can erase commits other people pushed, so use --force-with-lease, which refuses when the remote moved.
Common flags
| Flag | Meaning |
|---|---|
| -u | set the upstream so later pushes need no arguments |
| --force-with-lease | force, but stop if the remote moved since your last fetch |
| -f | force: overwrite the remote branch, commits of others included |
| --tags | push tags as well, which push does not do on its own |
| --delete <branch> | delete the branch on the server |
| --all | push every local branch |
| -n | dry run |
Examples
git push -u origin feature/loginpublishes the branch and remembers the pairing
git push --force-with-leasethe safe force, used after a rebase
git push origin --delete old-featureremoves the branch on the server
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git push do?
Sends your commits to a remote; --force overwrites the remote branch and can erase commits other people pushed, so use --force-with-lease, which refuses when the remote moved.
Q. How do I type it?
git push [-u] [--force-with-lease] <remote> <branch> — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
7 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-push