Save work with commits

Azure Repos | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018-TFS 2015

Visual Studio 2019 | Visual Studio 2017 | Visual Studio 2015

Git does not automatically snapshot your code as you make edits to files in your repo. You must tell Git exactly which changes you want to add to the next snapshot by staging those changes. After staging your changes, create a commit to save the snapshot to your repo.

In this tutorial you learn:

  • How Git tracks changes
  • What's in a commit
  • How to stage your changes
  • How to create a commit
  • How to update your last commit

How Git tracks changes

Git tracks file changes in your repo as you work, and separates the files in your repo into three categories:

  • Unmodified files - These files haven't changed since your last commit.
  • Modified files - These files have changes since your last commit, but you haven't yet staged for the next commit.
  • Staged files - These files have changes that will be added to the next commit.

Lifecycle of files in your repo between the three states

When you create a commit, only the staged changes and unchanged files are used for the snapshot. Changes to unstaged but modified files are kept, but the commit uses the unmodified version from the previous commit in its snapshot.

Commits are created in your local Git repository, so you don't have to worry about your changes being perfect. Continue to create commits as you work, pushing your changes to the team when they are ready to share.

What's in a commit

Commits include the following information:

  • A snapshot of the files saved in the commit. Git snapshots the contents of all files in your repo at the time of the commit—this makes switching versions very fast and helps Git merge changes.
  • A reference to the parent commit(s). Commits with multiple parents occur when branches are merged together.
  • A short and to the point message describing the changes in the commit. You enter this message when you create the commit.

Git uses the references between commits along with the file snapshots to maintain a complete record of development in your repo.

Learn more about Git history and how to review history to investigate changes made to your code.

Stage your changes

Git does not automatically add changed files to the snapshot when you create a commit. You must first stage your changes to let Git know which updates you want to add to the next commit. Staging lets you to selectively add files to a commit while excluding changes made in other files.

Ignore temp files, logs, and other files that might change on your local machine but you don't want to add to version control.


If you're using Visual Studio 2019 version 16.8 or later, try the Git version control experience. Learn more about how the Git experience compares with Team Explorer on this Side-by-side comparison page.

Visual Studio 2015 (Update 2) and 2017

Visual Studio keeps track of file changes to your project as you do your work. When you are ready to stage changes, open up the Changes view in Team Explorer.

Stage individual file changes by right-clicking a file in the Change view and selecting Stage. Staging a change creates a Staged Changes section in Team Explorer. Only changes in the Staged Changes section are added to the next commit.

Stage files for your next commit using Team Explorer


The Team Explorer Changes view had Included Files and Excluded Files sections before Visual Studio 2015 Update 2. The Changes view was updated in Visual Studio 2015 Update 2 for better compatibility with other Git tools.

Stage multiple files or folders by selecting them then right-clicking and choosing Stage or by dragging and dropping files from the Changes list into the Staged Changes list.

Ignore files by right-clicking and selecting Ignore this local item or Ignore this extension. This adds an entry to the .gitignore file in your local repo. If the ignored file was added to your repo in an earlier commit, ignoring the file will not remove it from the Changes list. See excluding and ignoring files section for more information on how to ignore files already tracked by Git.

Create a commit


If you're using Visual Studio 2019 version 16.8 or later, try the Git version control experience. Learn more about how the Git experience compares with Team Explorer on this Side-by-side comparison page.

Open the Changes view in Team Explorer.

Enter a commit message describing your changes and select Commit Staged to create a new commit that includes the changes listed in the Staged Changes section.

Create a commit from staged items in Visual Studio

Skip staging files if you just want to commit all changes listed by entering a commit message and selecting Commit All when you have no staged changes.

Commit all changes without staging them first in Visual Studio

When you commit in Visual Studio you can push the commit and sync the branch with a remote repository. These options are available in the drop-down on the Commit button.

Update your last commit

Amend your last commit to correct small errors without making a new commit.


Do not amend pushed commits. If you need to update pushed code, undo the changes with revert or create and push another commit.

  1. Open the Changes view in Team Explorer and stage your updated changes. You can amend just the commit message by leaving the staged changes empty.

  2. Enter the updated commit message and select Amend Previous Commit from the Actions drop-down.

    Amend a commit in Visual Studio

Next steps