Git add, commit, and push

Greg Foster
Greg Foster
Graphite software engineer

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.

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.

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.

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