I\'m trying to remove a previously tracked directory from git, which works, but it\'s being added back with each subsequent git add .
, git add -A
, etc.
gitignore - Specifies intentionally untracked files to ignore.
$HOME/.config/git/ignore, $GIT_DIR/info/exclude, .gitignore
Each line in a gitignore file specifies a pattern. When deciding whether to ignore a path, Git normally checks gitignore patterns from multiple sources, with the following order of precedence, from highest to lowest (within one level of precedence, the last matching pattern decides the outcome):
To ignore entire directory you should use /**
,
A trailing /** matches everything inside. For example, abc/** matches all files inside directory "abc", relative to the location of the .gitignore file, with infinite depth.
Or
You can ignore the entire directory by adding this line to your root .gitignore file:
/Dir_Name
Instead, you can add a /logs/.gitignore file containing this:
[^.]*
The directory will remain in your repo, but all files inside /directory will be ignored. Easy!
The steps you need to follows are,
Remove it from the project directory (without actually deleting it):
git rm --cached folder/*
Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):
$ cat .gitignore
# exclude everything except directory foo/bar
/*
!/foo
/foo/*
!/foo/bar