Read Anthropic’s case study about Graphite Reviewer

How to push to GitHub

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

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


Pushing code to GitHub is a fundamental skill for software developers using Git for version control. This guide covers everything from the basics of pushing a local repository to GitHub to more specific tasks like pushing changes, branches, and files using both the terminal and Visual Studio Code (VSCode).

Pushing to GitHub refers to the act of uploading your local repository changes to a remote repository hosted on GitHub. This enables collaboration, version tracking, and other features useful for both private projects and open-source work.

Here’s how you can push to the trunk branch on GitHub using the command line:

  1. Open your terminal.
  2. Navigate to your project directory.
    Terminal
    cd path/to/your/project
  3. Add the remote repository (if not already added):
    Terminal
    git remote add origin https://github.com/username/repository.git
  4. Stage your changes:
    Terminal
    git add .
  5. Commit your changes:
    Terminal
    git commit -m "Your commit message"
  6. Push your changes:
    Terminal
    git push origin main

To push a new or existing local branch to GitHub, follow these steps:

  1. Create a new branch (if necessary):
    Terminal
    git checkout -b new-branch
  2. Make your changes and commit them:
    Terminal
    git add .
    git commit -m "Commit message"
  3. Push the branch:
    Terminal
    git push origin new-branch

Visual Studio Code (VSCode) provides an integrated Git control that simplifies pushing changes to GitHub:

  1. Open your project in VSCode.
  2. Open the Source Control panel (click on the branch icon on the sidebar or press Ctrl+Shift+G).
  3. Stage your changes by clicking on the '+' icon next to each changed file or the "Stage All Changes" button at the top.
  4. Commit your changes by typing a message in the commit message box and pressing Ctrl+Enter.
  5. Push your changes by clicking on the '...' button at the top of the Source Control panel, selecting "Push" from the dropdown menu.

For more information, see this guide on pushing code from VS Code to GitHub.

  • Pushing a local repo to GitHub for the first time:

    Terminal
    git remote add origin https://github.com/username/repository.git
    git push -u origin main
  • Pushing changes to an existing repository: Follow the steps mentioned under "How to push to GitHub from the terminal".

  • Pushing a file to GitHub: If you want to push a specific file:

    Terminal
    git add filename
    git commit -m "Add filename"
    git push origin main
  • Pushing a new branch:

    Terminal
    git checkout -b branch-name
    git push -u origin branch-name
  • Check your branch: Always ensure you're on the correct branch before pushing by using git branch.
  • Secure your commits: Consider signing your commits with GPG for added security.

For more information, see this guide on the Git add, commit, and push workflow.

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2