This article will demonstrate how Git adds only modified changes and ignores untracked new files.
How Does Git Add Only Modified Changes and Ignore Untracked Files?
To add modified changes and ignore untracked files, first, move to the Git local repository. Next, create a file and move it to the staging index. After that, create another file and do not track it to the staging area. Lastly, add modified files to the staging area, skip untracked files with the help of the “$ git add -u” command, and commit the staged changes.
Let’s move ahead and implement the above-discussed scenario for better understanding!
Step 1: Open Git Bash Terminal
Launch the Git terminal using the Windows Start menu:
Step 2: Go to Git Repository
Use the following command and navigate to the required Git repository:
Step 3: Initialize Git Repository
Then, to initialize the current repository by running the following command:
Step 4: Create a File
Now, create a new text file through the “touch” command:
Step 5: Add File to the Staging Area
After that, add the untracked file to the Git staging area:
Step 6: Create Another File
Similarly, generate another text file by using the same procedure:
Step 7: Verify the Git Status
To view the tracked and untracked files, check the Git status through the provided command:
According to the below-listed output, we have one tracked file which is ready to commit and the other one is the untracked file:
Step 8: Track Modified File
To add only modified files to the staging area and skip new or untracked files, run the “git add” command with the “-u” option:
Step 9: Commit Changes
Execute the below-provided command to commit the staged changes:
Step 10: Check the Git Status
To verify if the untracked file is added to the Git repository or not, check the Git status:
As you can see, the untracked file is not added to the Git repository and exists in the working directory:
That’s all! We have compiled the easiest method of adding only modified changes and ignoring untracked files.
Conclusion
To add only modified changes and ignore untracked files, first, go to the Git local repository. Next, create a file and add it to the staging index. After that, create another file and do not add it to the staging area. Then, add modified files to the staging area, ignore unstaged files with the help of the “$ git add -u” command, and commit the staged changes. This article demonstrated the procedure of adding only modified changes and ignoring untracked files.