Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Practice for Adding .gitignore to Repo

Tags:

git

gitignore

What is the best practice regarding the .gitignore file with Git; should it be excluded from the repository or included? If it's conditional, what are the conditions for each circumstance?

like image 318
E-rich Avatar asked Jul 08 '11 14:07

E-rich


People also ask

Should .gitignore be added to repository?

Normally yes, . gitignore is useful for everyone who wants to work with the repository. On occasion you'll want to ignore more private things (maybe you often create LOG or something. In those cases you probably don't want to force that on anyone else.

Where should .gitignore be placed?

A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .

Should Gitignore be pushed to GitHub?

A . gitignore file lists all of the files that are local to a project that Git should not push to GitHub. A . gitignore always goes in the top level of the project directory, which is also called the project's 'root'.

What is the purpose of adding a .gitignore file to a Git repository?

gitignore file is a text file that tells Git which files or folders to ignore in a project. A local . gitignore file is usually placed in the root directory of a project. You can also create a global .


1 Answers

They should almost always be included, as their purpose is to ignore "output" files (compiled binaries, log files) which are going to be generated by anybody working with a clone of your project. They're meant to be version-controlled and included with the repository.

You should not use .gitignore files within the repository to ignore files that only appear for you, such as editor-specific swap files. You should be placing those rules in a global .gitignore file so that they apply to all repositories, or in .git/info/excludes.

like image 142
meagar Avatar answered Sep 23 '22 06:09

meagar