Section 3.5 Staging Changes
As you saw in the previous section, you now have modifications to your local files that have not been staged. The process of staging changes (i.e. adding the files to the stage) is illustrated in Figure 3.5.1. Recall from Figure 3.4.1 that the blue dot in Local Files represents the changes you made. In Figure 3.5.1, those changes are staged and will be made into a commit that is added to your feature branch in the next section.

Diagram showing that the git stage command results in change to the local files being represented in the staging area in preparation for being committed.
Exercises
The exercises in this section will walk you through staging the changes you made to your Local Files.
The
git stage <file>
command adds the indicated file to the stage, preparing it to become a part of the next commit.
2.
3.
How many files are not staged?
- 0
- Correct! After issuing the
git stage
command the file will be staged. - 1
- Did you change more than 1 file by accident? Verify that you only changed the file specified in your issue.
- 2
- Did you change more than 1 file by accident? Verify that you only changed the file specified in your issue.
- Cannot be determined from the output provided by the
git status
command. - The
git status
command will show you all unstaged and staged files.
4.
How many files are listed as ready to be committed?
- 0
- If you issued the
git stage
command properly the file you changed should appear as ready to be committed. - 1
- Correct! After issuing the
git stage
(orgit add
) command the file will be staged. - 2
- Did you change more than 1 file by accident? Verify that you only changed the file specified in your issue.
- Cannot be determined from the output provided by the
git status
command. - The
git status
command will show you all unstaged and staged files.
5.
Run the
git diff
command again. What output is produced?
- No output is produced.
- Correct! There are no differences because your changes were staged.
- It shows the file name that I changed.
- If you are seeing the file name you changed it means either you made additional changes after the
git stage
command was done or yourgit stage
command did not work properly. - It shows the code I added in green.
- If you are seeing code changes it means either you made additional changes after the
git stage
command was done or yourgit stage
command did not work properly. - It shows the code I deleted in red.
- If you are seeing code changes it means either you made additional changes after the
git stage
command was done or yourgit stage
command did not work properly.
The
git diff --staged
command will show you the differences between the staged changes and the most recent commit. Try this command now.
Note that git also has a
git add
command that is equivalent to git stage
. So, you can add files to the stage using either git stage
or git add
. These activities will use git stage
because it seems more descriptive of what is happening. However, you are likely to see git add
used in other resources, so it is worth knowing that they are equivalent.
You have attempted 1 of 4 activities on this page.