Reputation: 1424
I am still struggling with Git. I have git local repos. It look like below:
project
- .git
- .gitignore
- child [directory]
- some files
.gitignore:
target/
logs/
.DS_Store
And I did.
git rm --cached .
git add .
I expected that the files and directories in .gitignore would not be tracked but it did not work. Nothing in the files were ignored.
What can I fix this?
Your answer would be appreciated.
Upvotes: 0
Views: 525
Reputation: 9197
There are 3 places where you can configure ignoring files in git (and .git/.gitignore
is not one of them). From highest to lowest precedence, they are:
.gitignore
in the same directory as the path, or in any parent directory. .gitignore
s are committed and versioned along with the rest of the project. There is commonly one in the root of the repository, but you can have as many as one per directory. This file should contain project specific things to ignore (build output and such)..git/info/exclude
. This file is not versioned and will only impact that repository.core.excludesfile
. It is typically placed in a users home directory named something like ~/.gitignore_global
, but could be named anything. This file is also not versioned. It applies to all git repositories. This file should contain project agnostic things to ignore (editor files, operating system files).In your case, you should create a .gitignore
in the root of your project with the following in it:
target/
logs/
And then create a global gitignore for the .DS_Store
rule in ~/.gitignore_global
:
.DS_Store
Run git config --global core.excludesfile ~/.gitignore_global
to enable that file.
See this helpful GitHub article and gitignore(5) for more information.
Upvotes: 2