Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (29.3k points)

I have a git repository that's used only to hold graphics and sound files used in several projects. They are all in one directory without sub-directories. Now I just created a script to copy these assets over from another, structured directory, with several levels of sub-directories.

Now I only want the (source) hierarchical file structure to be tracked by git, and the (target) flat directory (with all the files in one pile) should be ignored.

I've added the target directory to .gitignore, but git is still tracking changes in it. I thought if I commit the deletion of the old file in the target directory, git might stop tracking the new contents (copied in by the script), but it doesn't.

How do I make git forget about the target directory?

1 Answer

0 votes
by (50.2k points)

There is a command which helps git to untrack your directory and all files under it: 

git rm -r --cached <your directory>

This will not delete the directory it will just untrack the directory.

-r is used for the removal of files under the directory.

The --cached option causes the files to only be removed from git's index, not your working copy. By default git rm <file> would delete <file>.


Additional info: if you need to untrack the files from git temporarily please go through this answer:

Browse Categories