Skip to content

Push

In one line

Pushing uploads your local commits to a remote repository so others can see and pull them.

In simple words

git push sends your local commits to a remote repository. After you commit changes locally, they exist only on your machine. Pushing publishes them to the server (e.g. GitHub) so collaborators can see and pull them.

The typical command is git push origin main — push the local main branch to the origin remote. If the remote has commits you do not have locally, the push is rejected. You must pull first to integrate the remote changes, then push again.

Pushing is a one-way upload of your history. It does not merge or modify your local files — it only transfers commits you already have. The first push of a new branch uses git push -u origin <branch> to set up tracking, so future git push commands work without arguments.

Example

bash
# Push local main to origin
git push origin main

# First push of a new branch (sets up tracking)
git push -u origin feature/login

# After tracking is set up, just:
git push

git push uploads local commits to the remote. -u sets up tracking for a new branch.

How it works

  1. You commit changes locally.
  2. git push origin <branch> uploads your commits to the remote.
  3. If the remote has commits you lack, the push is rejected — pull first.
  4. On success, the remote branch now matches your local branch.

Related terms

Related Resources

Related Lessons

Learn the fundamentals

Deepen your understanding with structured lessons on this topic.

View lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary