git push
Send your commits to the server
What it does
git push sends the new commits of the current branch to the remote. The first time you push a new branch, say where to: git push -u origin <branch>. -u remembers the link, and after that a plain git push and git pull are enough.
If the server has commits you do not, push refuses: get them with git pull first, then push again. After git commit --amend, git reset or git rebase your history differs from the server's, and a plain push fails too.
Careful. --force and --force-with-lease replace the branch on the server with yours, and other people's commits you do not have are lost. Use them only on your own branches, and prefer --force-with-lease: it refuses if the server has commits you have not seen yet.
Syntax
git push
git push -u <remote> <branch>
git push --force-with-leaseExamples
Push main to origin and remember the link to that branch
git push -u origin mainsame as:
git push --set-upstream origin mainpush— send commits-u— remember the upstream for the next pushesorigin main— remote repository and branch
Push new commits to the already linked branch
git pushpush— send commits to the server
Related commands
- git pull — Download changes from the server and merge them into the current branch
- git remote — List and add remote repositories
- git commit — Save the staged changes to history as a new commit