Back
GitoryxGitoryx
Beginner8 min read

Git Push: Upload Your Commits to a Remote Repository

git push sends your local commits to a remote repository, making them available to your teammates. This guide covers standard pushes, setting upstream branches, force pushing safely, and what to do when a push is rejected.

The Problem

You committed your changes locally but your teammates can't see them. You run `git push` and get an error: 'rejected — non-fast-forward'. Now what?

git push is how local work becomes visible to the rest of the team. But pushing to a shared branch requires care: a rejected push usually means someone else pushed first, and you need to integrate their changes before yours will be accepted.

Common mistakes developers make with this:

  • Getting a 'rejected — non-fast-forward' error and not knowing why
  • Force-pushing to a shared branch and overwriting teammates' commits
  • Forgetting to set the upstream branch when pushing a new branch for the first time
  • Pushing to the wrong remote or branch

Gitoryx: Gitoryx shows you whether your branch is ahead of or behind origin before you push, and warns you if a force push would overwrite remote changes.

What is Push: Upload Your Commits to a Remote Repository?

`git push` uploads your local commits to a remote repository branch. If the remote branch has commits your local branch doesn't have, the push will be rejected until you integrate those changes.

Step-by-Step Guide

1

Push your current branch

If your branch already has a tracking remote, a plain `git push` is enough.

bash
git push

Run `git status` first — it tells you how many commits ahead of origin you are.

2

Push a new branch and set its upstream

When you push a brand new local branch for the first time, use `-u` to set the remote tracking branch. Future `git push` and `git pull` commands will then work without arguments.

bash
git push -u origin feature/user-auth
3

Push to a specific remote and branch

Explicitly specify the remote and target branch name.

bash
git push origin feature/user-auth

# Push local branch to a differently-named remote branch
git push origin feature/user-auth:feature/user-auth-v2
4

Handle a rejected push (non-fast-forward)

If the remote has commits you don't have locally, your push will be rejected. You need to integrate the remote changes first.

bash
# Error:
# ! [rejected] main -> main (non-fast-forward)

# Integrate remote changes first:
git pull --rebase origin main

# Then push again:
git push

Never use `git push --force` on a shared branch (main, develop) to resolve this — you'll overwrite your teammates' commits.

See this workflow in Gitoryx — Gitoryx screenshot

See this workflow in Gitoryx. See 'ahead/behind' status for every branch before pushing

Free download
5

Force push safely with --force-with-lease

If you've rewritten your own feature branch (via rebase or amend) and need to push the rewritten history, use `--force-with-lease` instead of `--force`. It refuses the push if someone else has pushed to the branch since your last fetch.

bash
git push --force-with-lease origin feature/user-auth

Force-pushing is only safe on branches that only you are working on. Never force-push to shared branches.

6

Delete a remote branch

After a branch is merged, clean it up on the remote.

bash
git push origin --delete feature/user-auth

Common Mistakes to Avoid

Force-pushing to a shared branch

`git push --force` on `main` or `develop` overwrites the remote history and leaves teammates with a diverged history they can't easily reconcile.

Fix: Always pull and rebase before pushing to shared branches. Use `--force-with-lease` only on your personal feature branches.

Forgetting `-u` on first push

Without setting the upstream, every future `git push` on that branch requires the full `git push origin <branch>` command.

Fix: Always use `git push -u origin <branch>` the first time you push a new branch.

Pushing sensitive files accidentally

Once a file containing an API key or password is pushed, it's in the history — even if you delete it in a later commit.

Fix: Use `.gitignore` to exclude sensitive files before they're ever added. Rotate any credentials that were accidentally exposed.

Gitoryx — visual Git client for macOS, Windows & Linux
GitoryxGitoryx — macOS, Windows & Linux

Push branches safely with Gitoryx

  • See 'ahead/behind' status for every branch before pushing
  • One-click push with upstream tracking set automatically
  • Warning dialog before any force push operation
  • Delete remote branches directly from the branch manager
Download Gitoryx — FreemacOS · Windows · Linux · No subscription

Frequently Asked Questions

Why is my `git push` rejected?

The most common reason is 'non-fast-forward': the remote has commits your local branch doesn't have. Run `git pull --rebase` to integrate the remote changes, then push again.

What is the difference between `git push --force` and `--force-with-lease`?

`--force` overwrites the remote branch regardless of what's there. `--force-with-lease` checks that nobody else pushed to the branch after your last fetch — it's a safer option that prevents accidentally overwriting teammates' work.

How do I push a local branch to a remote for the first time?

Use `git push -u origin <branch-name>`. The `-u` flag sets the upstream tracking so future pushes and pulls work without arguments.

How do I delete a remote branch?

Run `git push origin --delete <branch-name>`. You can also delete it from the GitHub or GitLab web interface.

See it in action with Gitoryx

Everything in this tutorial is faster and clearer with a visual Git client. Gitoryx is free, runs natively on macOS, Windows, and Linux, and built for developers who want to move fast without breaking things.