# Git Push

URL: https://softwaredictionary.org/terms/git-push
Category: Version Control
Last updated: 2026-09-30

In short: Git push is a Git command that uploads your local commits to a remote repository, updating the matching branch there so others can see and use your work.

## What is git push?

`git push` sends commits from your local repository to a remote repository, such as one on a code hosting platform or a company server. Until you push, your commits exist only on your own machine; after pushing, teammates can pull them, CI pipelines can test them, and you can open a pull request. A typical command is `git push origin main`, which means 'send my `main` branch to the remote named `origin`'.

The first time you push a new branch, `git push -u origin <branch>` also sets it as the branch's upstream, so later a plain `git push` or `git pull` knows where to go. By default, Git only accepts a push that is a fast-forward, meaning the remote branch's latest commit is already part of your history. If someone else pushed first, Git rejects your push, and you need to pull their changes, resolve any conflicts, and push again.

Pushing is like publishing a draft to a shared folder: until you do, your edits are private, and afterward everyone can build on them. Hosting platforms can add rules on top of this, such as protected branches that refuse direct pushes to `main` and require a reviewed pull request instead, and server-side Git hooks can reject pushes that break team policies.

Push is often confused with commit. `git commit` saves a snapshot locally and `git push` shares commits that already exist, so you always commit before you push. Force pushing with `git push --force` overwrites the remote branch with your version even if that deletes other people's commits, so it should never be used on shared branches; after rebasing your own branch, prefer `git push --force-with-lease`, which refuses to overwrite commits you haven't seen.

## Key takeaways

- `git push` uploads local commits to a branch on a remote repository.
- `git push -u origin <branch>` publishes a new branch and sets its upstream for later pushes and pulls.
- Git rejects pushes that are not fast-forwards; pull first, then push again.
- `--force` can erase other people's work, while `--force-with-lease` refuses to overwrite commits you haven't fetched.
- Commits stay local until pushed, and tags must be pushed explicitly.

## Example: Publishing and updating a branch

```bash
# Publish a new branch and set its upstream
git switch -c feature/search
git commit -am "Add search endpoint"
git push -u origin feature/search

# Later pushes on the same branch need no arguments
git push

# Rejected because the remote has new commits? Sync, then push again
git pull --rebase
git push

# After rebasing your own branch, overwrite it safely
git push --force-with-lease
```

## Frequently asked questions

**Why was my git push rejected?**

Usually because the remote branch has commits you don't have yet, so your push would not be a fast-forward. Run `git pull` or `git pull --rebase`, resolve any conflicts, and push again; other causes include protected branches and missing write permission.

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

`--force` replaces the remote branch with yours no matter what is on it. `--force-with-lease` first checks that the remote branch is still where you last saw it and refuses if someone has pushed new commits in the meantime, so you can't wipe out their work by accident.

**How do I delete a remote branch?**

Run `git push origin --delete <branch>`. This removes the branch from the remote only, so delete your local copy separately with `git branch -d <branch>`.

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
