Graphite Reviewer is now Diamond

Understanding the differences between `git commit` and `git push`

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite


Note

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


In Git, managing source code changes involves several key steps—staging, committing, and pushing changes to a remote repository. Each step serves a specific purpose in the lifecycle of code changes, ensuring detailed tracking and efficient collaboration.

git commit is a local operation; it affects only your local repository and does not interact with the remote repository. Until they're pushed, commits exist only on your local machine. Whereas git push is a network operation that transfers commits from your local repository to a remote repository. This makes these commits accessible from the remote repository. Let's dig into this a bit deeper:

  • Purpose: Prepares changes for a commit. It adds modifications from your working directory to the staging area (also known as the index). This area acts as an intermediary snapshot of your work, allowing you to review and finalize changes before they are committed to your project history.
  • Usage:
    Terminal
    git add <file> # Adds a specific file
    git add . # Adds all changed files in the directory
  • Purpose: Takes everything from the staging area and records it in the repository's history as a snapshot. This step is important as it captures the state of a project at a point in time.
  • Usage:
    Terminal
    git commit -m "Descriptive message about the change"
  • Purpose: Uploads committed changes from your local repository to a remote repository. This is essential for sharing changes with others and effectively collaborating on projects.
  • Usage:
    Terminal
    git push origin main # Pushes changes from the local main branch to the remote main branch

The Graphite CLI builds on Git's functionality by facilitating the management of stacks of changes, making it simpler to handle multiple dependent changes across different branches.

  • Purpose: Submits a stack of changes as a series of pull requests to GitHub. This command is particularly useful for managing complex workflows that involve multiple dependent branches.
  • Usage:
    Terminal
    gt submit --stack # Submits all branches in your current stack
  1. Staging changes:
    Terminal
    git add modified_file.txt
  2. Committing the staged changes:
    Terminal
    git commit -m "feat: add new feature to modified_file"
    This records your changes locally on the main branch, showing the commit hash and changes summary.
  • After committing, to share your changes:
    Terminal
    git push origin main
    This transfers your commits to the remote repository, updating it with your latest changes.
  • Commit often: Each commit should encapsulate a coherent piece of work. This makes it easier to track changes and roll back if necessary.
  • Push selectively: Push changes to the remote repository when they are ready to be shared or when collaboration is required.

The git commit command is pivotal for recording changes locally, allowing for detailed tracking and control over the project's evolution. The git push command plays a crucial role in sharing these changes remotely. Integrating Graphite with commands like gt submit further enhances this workflow, offering advanced management capabilities for complex project structures.

For further reading on Git's best practices and advanced features, consider visiting Git's official documentation. And to learn more about the Graphite CLI, check out our quick start guide.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Built for the world's fastest engineering teams, now available for everyone