What is .gitignore exactly?
.gitignore
tells git which files (or patterns) it should ignore. It's usually used to avoid committing transient files from your working directory that aren't useful to other collaborators, such as compilation products, temporary files IDEs create, etc.
You can find the full details here.
It's a list of files you want git to ignore in your work directory.
Say you're on a Mac and you have .DS_Store files in all your directories. You want git to ignore them, so you add .DS_Store as a line in .gitignore. And so on.
The git docs will tell you all you need to know: http://git-scm.com/docs/gitignore
When you are doing a commit you do not want accidentally include temporary files or build specific folders. Hence use a .gitignore
listing out items you want to ignore from committing.
Also, importantly git status
is one of the most frequently used command where you want git status
to list out the files that have been modified.
You would want your git status
list look clean from unwanted files. For instance, I changed a.cpp, b.cpp, c.cpp, d.cpp & e.cpp
I want my git status
to list the following:
git status
a.cpp
b.cpp
c.cpp
d.cpp
e.cpp
I dont want git status
to list out changed files like this with the intermediary object files & files from the build folder
git status
a.cpp
b.cpp
c.cpp
d.cpp
e.cpp
.DS_Store
/build/program.o
/build/program.cmake
Hence, to get myself free from git status
to list out these intermediate temporary files & accidentally committing them into the repo, I should create a .gitignore
which everyone does. All I need to do list out the files & folders in the .gitignore
that I want to exclude from committing.
Following is my .gitignore
to avoid committing unnecessary files
/*.cmake
/*.DS_Store
/.user
/build