Read Anthropic’s case study about Graphite Reviewer

Git add, commit, and push

Greg Foster
Greg Foster
Graphite software engineer


Note

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


This guide focuses on the essential Git commands git add, git commit, and git push, providing a clear understanding of each step and how they work together to manage your code changes.

The git add, git commit, and git push commands are fundamental to managing changes in Git, allowing you to stage local changes, and push remote repository updates.

git add is the command used to start tracking changes made in your repository. It stages changes for the next commit, meaning it marks modifications in your working directory to be stored in a snapshot with the next commit.

Join 20,000+ developers at top companies
Stop wrestling with Git commands
The Graphite CLI takes all the pain out of Git, allowing you to ship faster and stop googling Git commands.
main
diff1
diff2

To stage a single file, run:

Terminal
git add <file-name>

To stage all changes in the directory, run:

Terminal
git add .

Once changes are staged with git add, git commit is used to save snapshots of these changes to the project's history. This snapshot allows you to record versions of the codebase at incremental points in time.

To commit staged changes, use:

Terminal
git commit -m "Commit message describing the changes"

After committing changes locally, git push uploads your commits to a remote repository, storing them in an online server, providing redundancy and making them available to other developers.

To push the current branch and its commits to the remote repository, use:

Terminal
git push origin <branch-name>

If you're pushing to the same branch you've configured as the upstream branch, you can simply use:

Terminal
git push

The upstream branch is the branch that lives on the remote repository, corresponding to your local branch.

  • git add: Stages changes; it tells Git that you want to include updates in the next commit. However, changes are not yet recorded in the repository history.
  • git commit: Takes whatever is currently in the staging area and wraps it in a new commit snapshot, which is then part of your local repository.
  • git push: Sends your committed changes to a remote repository, sharing them with others and backing them up on a server.
Join 20,000+ developers at top companies
The best engineers use Graphite to simplify Git
Engineers at Vercel, Snowflake & The Browser Company are shipping faster and staying unblocked with Graphite.
main
diff1
diff2

While it's generally good practice to review each step, you can streamline your workflow by running all three steps in a single command:

Terminal
git add -A && git commit -m "Your commit message" && git push origin main

Remember to replace "Your commit message" with an actual message and adjust the branch name if needed.

  1. Always pull before you push to ensure there are no conflicts with the remote repository.
  2. Keep your commits small and focused; this makes it easier to identify and resolve issues.
  3. Write meaningful commit messages; this is crucial for understanding the history of a project.

For further reading see the official Git documentation on add, commit, and push.

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