Is it possible to start tracking files in git without adding them to the index?
I have new files which I'd like to survive a git clean
, but will likely change before the next commit. Do I simply add them to the index now, and then add them again later just before the commit?
When you start a new repository, you typically want to add all existing files so that your changes will all be tracked from that point forward. So, the first command you'll typically type is "git add ." (the "." means, this directory. So, it will add everything in this directory.) I'll type "git add ." and press Enter.
You have to add the untracked files of the repository by using the “git add” command and run the “git stash” command to save the untracked file and clean the current directory for working by removing the untracked file from the repository folder.
Tracking New Files The git add command takes a path name for either a file or a directory; if it's a directory, the command adds all the files in that directory recursively.
adds both tracked and untracked files. Let's demonstrate this, by creating a file in the current directory as well as a file in a sub-directory. Now let's change into the sub-directory and run git add . If we run git status , we'll notice only the file in the sub-directory was added.
Seems like you're looking for git add --intent-to-add
(or git add -N
). From the official git add
documentation:
-N --intent-to-add
Record only the fact that the path will be added later. An entry for the path is placed in the index with no content. This is useful for, among other things, showing the unstaged content of such files with
git diff
and committing them withgit commit -a
.
See the What does git add --intent-to-add or -N do and when should it be used? question for more information.
You can stage the files using git add
, then git reset
them prior to the commit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With