Search anything:

Git add command: track a new file

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

Reading time: 15 minutes

In this article, we will explore how Git tracks new files using the git add command.

OpenGenus loves Git

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.

create new file touch command

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.

git status

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.

git add new file

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.

git status

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.

OpenGenus Tech Review Team

OpenGenus Tech Review Team

The official account of OpenGenus's Technical Review Team. This team review all technical articles and incorporates peer feedback. The team consist of experts in the leading domains of Computing.

Read More

Improved & Reviewed by:

Git add command: track a new file
Share this