Git

Start Tracking a File in Git Without Adding to the Index

Git is the most useful tool for tracking the changes made in the source code files during software development. It is specially designed for coordinating work among developers. However, it can be utilized to track modifications in any set of project files. Additionally, you can also perform tracking without adding changes to the staging index.

This blog will provide the easiest way for tracking a file without adding to the index in Git.

How to Track a File Without Adding to the Index in Git?

To track a file without adding to the index in Git, try the below-listed instructions:

  • Switch to the Git repository.
  • Check the empty path default value from the Git configuration file and update it through the “git config” command.
  • Create and update a new file.
  • Run the “git add –intent-to-add” command to stage the file without adding an index.
  • View the repository’s current status.
  • Push the changes to the Git repository by committing them.

Step 1: Navigate to Particular Repository
First, go to the Git local repository with the help of the “cd” command:

$ cd "C:\Users\nazma\Git\dir_1"

Step 2: Check Default Empty Path Setting
Next, execute the “git config” command and view the default value of the empty path:

$ git config advice.addEmptyPathspec

According to the below-given output, the default value is not added yet:

Step 3: Update Configuration File
Now, update the configuration file with the value of the empty path as “false” by running the provided command:

$ git config advice.addEmptyPathspec false

Step 4: Create and Update File
Then, use the “echo” command to create and update a new file:

$ echo "My text file" >> "file5.txt"

Step 5: Track File
After that, add the desired file by running the “git add” command:

$ git add --intent-to-add

Here, the “–intent-to-add” option is used for adding those changes which path will be added later:

Step 6: Check Status
Next, execute the “git status .” command to view the current working repository status:

$ git status .

According to the below-given output, the path of the newly created file is not added to the Git repository:

Step 7: Git Commit Changes
Lastly, push the added changes to the Git repository through committing with the help of the “git commit” command along with the “-a” option for all:

$ git commit -a

After executing the above-stated command, the default text editor will appear on the screen and ask for a commit message. For instance, we have typed “add changes” as a commit message:

It can be observed that the local repository files are also pushed to the Git repository:

That was all about the way to start tracking a file in Git without adding to the index.

Conclusion

To start tracking a file in Git without adding to the index, first, navigate to the Git repository and check the empty path default value from the Git configuration file. Next, update it by utilizing the “git config” command. After that, create and update a new file and add it by running the “git add –intent-to-add” command. Lastly, check the repository’s current status and commit to the Git repository. This blog explained the easiest way to start file tracking without adding to the index in Git.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.