Skip to main content
Remote Repositories

git push

Upload local commits to a remote repository

Practical Example

git push origin main                    # push main branch
git push -u origin feature-login        # push and set upstream
git push origin --delete old-branch     # delete remote branch

Command Overview & How It Works

Sends committed changes from your local repository to a remote, making them available to collaborators. The basic syntax is git push <remote> <branch>, which pushes the specified branch to the matching branch on the remote. If the remote has commits you do not have locally, Git rejects the push — you must pull or fetch first. Use git push -u origin main to set the upstream tracking relationship, which lets you use just git push thereafter. Use git push --force (or -f) to overwrite the remote history — dangerous and should only be used on private or feature branches after rebasing. Use git push --dry-run to see what would be pushed without actually doing it. Use git push origin --delete <branch> to delete a remote branch. Never force-push to shared branches like main.

Practical Tips

  • Use git push -u origin main the first time so later pushes can simply be git push.
  • If the remote rejects your push, pull or fetch first — the remote has commits you do not have locally.
  • Never force-push to shared branches; if you must, prefer --force-with-lease, which refuses if the remote has moved.

Related Commands in Remote Repositories