Skip to main content
⚡ OpenDevDocs
Git
gitgitGuideBeginner

git push — Uploading Local Commits to Remotes

Uploading commits with git push: upstream tracking (-u), safe force pushes (--force-with-lease), and resolving non-fast-forward rejections.

Verified: 2026-09-30
Platforms:
all
#git#push#remotes#force-push#safety

git push — Uploading Local Commits to Remotes

The git push command uploads local branch commits to the corresponding remote repository on GitHub or a Git server.


1. Syntax and Upstream Tracking (-u)

When pushing a newly created branch for the very first time, use the -u (set-upstream) flag to link your local branch to the remote branch:

# 1. First push of a new feature branch:
git push -u origin feat/user-auth

# 2. Subsequent pushes on this branch (upstream is saved):
git push

2. Safe Force Pushing (--force-with-lease)

If you used git rebase or git commit --amend on your local feature branch, Git will reject normal git push because commit SHA hashes diverged.

Always Use --force-with-lease:

--force-with-lease checks if anyone else has updated the remote branch before overriding it. If new commits were pushed by a teammate, Git will abort and protect their work:

git push --force-with-lease origin feat/user-auth

On this page