Live streamJoin us for "State of code review 2024" on July 18thRegister today

How to use git push origin

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


The git push origin command transfers commits from your local repository to a remote repository. This command updates the remote branch with commits from your current branch. This guide will cover how to use git push origin and its variations to manage your code in a remote repository effectively.

In Git, "origin" is the default name given to the remote repository from which your local repository was cloned. You can push your changes to this remote repository using the git push origin command.

To push the current branch to the corresponding remote branch run:

Terminal
git push origin

This command pushes changes from the local branch you are currently on to the remote branch with the same name.

If you want to push changes to a specific branch, you can specify the branch name:

Terminal
git push origin <branch-name>

For example, to push to a branch named feature:

Terminal
git push origin feature

If you are working with the main branch and ready to update the remote main branch, use:

Terminal
git push origin main

This command specifically targets the main branch, ensuring that your local main branch's changes are pushed to the remote main branch.

The -u flag sets the upstream tracking information for the branch. This means that once you set the upstream branch with this command, you can use git push and git pull without specifying the branch in future commands.

Terminal
git push -u origin <branch-name>

For example, to set upstream tracking for a branch named feature, run:

Terminal
git push -u origin feature

To set the upstream tracking for the main branch, ensuring that future pushes and pulls target this branch by default, use:

Terminal
git push -u origin main

Let's consider you have a local branch named feature that you've been working on and are now ready to push to the remote repository. Here's how you would push these local changes to the remote:

  1. Check the current branch:

    Terminal
    git branch

    This command will show you which branch you are currently on.

  2. Switch to the feature branch (if not already on it):

    Terminal
    git checkout feature
  3. Push the feature branch to origin with upstream tracking:

    Terminal
    git push -u origin feature

    This configures the feature branch to track the remote feature branch, simplifying future push and pull commands.

  4. Verify that the push was successful:

    Terminal
    git status

    This will confirm that everything is up-to-date and has been pushed correctly.

For further reading see the official Git documentation.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Get started

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2