How can I add changes to the staging area?

Question

The third step of this exercise asks me to add the changes to the staging area in Git, how do I do this?

Answer

Recall that we do git add <filename.extension> to add a file to the staging area.

If our file name was ‘homework.txt’, we’d type git add homework.txt and, if it was successful, nothing would happen in the terminal after pressing enter. If there’s an issue, Git will usually print a handy error message that sometimes include steps to fix the issue or suggestions.

10 Likes

Hi, I still don’t get why we need to add the changes to the staging area in Git when we’ve already added scene-1.txt into the staging area in the previous exercise. Do we have to keep on "git add " in bash every time we make changes in the file?

11 Likes

In the previous exercise you only added that version of the file ( the one that contains only one sentence ). When you use git diff in this exercise after adding a second sentence it shows you the difference you made, namely the second sentence. If you use git add one more time the final version will be added. In the beginning of this exercise the first sentence is in the staging area and the second sentence is in the working area. At the end both are in the staging area.

22 Likes