Where does the .gitignore file belong?

2019-01-29 17:11发布

问题:

Does the .gitignore file belong in the .git folder structure somewhere or in the main source files?

回答1:

Put .gitignore in the working directory. It doesn't work if you put it in the .git (repository) directory.

$ ls -1d .git*
.git
.gitignore


回答2:

As the other answers stated, you can place .gitignore within any directory in a Git repository. However, if you need to have a private version of .gitignore, you can add the rules to .git/info/exclude file.



回答3:

You can place .gitignore in any directory in git.

It's commonly used as a placeholder file in folders, since folders aren't usually tracked by git.



回答4:

When in doubt just place it in the root of your repository. See https://help.github.com/articles/ignoring-files/ for more information.



回答5:

If you want to do it globally, you can use the default path git will search for. just place it inside a file named "ignore" in the path "~/.config/git"

(so full path for your file is: ~/.config/git/ignore)



回答6:

Also, if you create a new account on Github you will have the option to add .gitignore and it will be setup automatically on the right/standard location of your working place. You don't have to add anything in there at the begin, just alter the contents any time you want.



回答7:

You may also find a global .gitignore directly at the ~ path if you haven't created it in your folder project. This file is taken into account by all your .git projects.



标签: git gitignore