Get this book -> Problems on Array: For Interviews and Competitive Programming
Reading time: 15 minutes
In this article, we will explore how Git tracks new files using the git add command.
In a git repository, we realize that we want to add a new file into that repository called opengenus_project. So let us add this new file to the repository by typing touch rockets.txt.
If we run the git status command, we now see that the rockets.txt file is now showing under the untracked files. Remember, untracked means that Git sees a new file that didn't exist in our last commit snapshot.
Now Git won't track anything unless we explicitly tell it to do so, but Git does provide us with some helpful information on how to add this untracked file. The bottom message says, nothing added to commit, but untracked files present. Git then lets us know how to add an untracked file by using git add, and then the name of the untracked file. So let's start tracking this file by typing git add rocket.txt.
If we now run git status, we now see that the rocket.txt file is showing as a new file being tracked, and that it's a new change waiting to be committed.
Modified files that have been added are now in our staged state. Git has provided us with another message that says use git reset HEAD, and then file, to unstage. Resetting or removing files from the staged area is something we're going to cover in the next article. For now, we just want to commit this new file. We can tell that this file is staged, because it's now under the Changes to be committed section.