Git Cheat Sheet · Synchronize

Publish your commits

git push · git push -u origin <branch>

git push sends your branch's commits to the remote. For a new branch, git push -u origin <branch> creates it on the remote and links it to your local branch: later pushes need no arguments.

What it does

Sends the commits of the current branch to the remote; on the first push, the branch is created there.

A use case

Your feature is committed locally and you want to open a pull request.

On the command line

git push
Sends the current branch to its tracked branch.
git push -u origin <branch>
First push of a branch, which links it to its remote version.
git push origin <tag>
Publishes a tag.
git push --force-with-lease
Force push, only if nobody has pushed in the meantime.

In Merathon

  1. "Push" button in the toolbar: the badge shows the number of commits to push.

Frequently asked questions

Why is git push refused (rejected, fetch first)?

The remote has commits you do not have. Run git pull (or git pull --rebase), resolve any conflicts, then push again.

How do I undo a git push?

On a shared branch, git revert <commit> then push: history is not rewritten. On your own branch, you can also git reset then force the push.

See also