Home·Terminal commands

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

FlagMeaning
-uset the upstream so later pushes need no arguments
--force-with-leaseforce, but stop if the remote moved since your last fetch
-fforce: overwrite the remote branch, commits of others included
--tagspush tags as well, which push does not do on its own
--delete <branch>delete the branch on the server
--allpush every local branch
-ndry run

Examples

git push -u origin feature/login

publishes the branch and remembers the pairing

git push --force-with-lease

the safe force, used after a rebase

git push origin --delete old-feature

removes 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