I just did a git init
on the root of my new project.
Then I created a .gitignore file.
Now, when I type "git status", ".gitignore" appears in the list of untracked files. Why is that?
I just did a git init
on the root of my new project.
Then I created a .gitignore file.
Now, when I type "git status", ".gitignore" appears in the list of untracked files. Why is that?
After you add the .gitignore
file and commit it, it will no longer show up in the "untracked files" list.
git add .gitignore
git commit -m "add .gitignore file"
git status
The .gitignore file should be in your repository, so it should indeed be added and committed in, as "git status" suggests. It has to be a part of the repository tree, so that changes to it can be merged and so on.
So, add it to your repository, it should not be gitignored.
If you want to store the list of ignored filed outside of your git tree, you can use .git/info/exclude file. It is applied only to your checkout of the repo.
The idea is to put files that are specific to your project into the .gitignore file and (as already mentioned) add it to the repository. For example .pyc and .o files, logs that the testsuite creates, some fixtures etc.
For files that your own setup creates but which will not necessarily appear for every user (like .swp files if you use vim, hidden ecplise directories and the like), you should use .git/info/exclude (as already mentioned).
You could actually put a line ".gitignore" into your ".gitignore" file. This would cause the ".gitignore" file to be ignored by git. I do not actually think this is a good idea. I think the ignore file should be version controlled and tracked. I'm just putting this out there for completeness.
You can also have a global user git .gitignore file that will apply automatically to all your repos. This is useful for IDE and editor files (e.g. swp and *~ files for Vim). Change directory locations to suite your OS
1) Add to your ~/.gitconfig file
[core]
excludesfile = /home/username/.gitignore
2) Create a ~/.gitignore file with file patterns to be ignored
2) Save your dot files in another repo so you have a backup (optional).
Any time you copy, init or clone a repo your global gitignore file will be used as well
Of course the .gitignore file is showing up on the status, because it's untracked, and git sees it as a tasty new file to eat!
Since .gitignore is an untracked file however, it is a candidate to be ignored by git when you put it in .gitignore!
So, the answer is simple: just add the line:
.gitignore # Ignore the hand that feeds!
to your .gitignore file!
And, contrary to August's response, I should say that it's not that the .gitignore file should be in your repository. It just happens that it can be, which is often convenient. And it's probably true that this is the reason .gitignore was created as an alternative to .git/info/exclude, which doesn't have the option to be tracked by the repository. At any rate, how you use your .gitignore file is totally up to you.
For reference, check out the gitignore(5) manpage on kernel.org.
Just incase someone else has the same pain we had. We wanted to exclude a file that had already been committed.
This post was way more useful: http://stackoverflow.com/questions/1158857/working-with-git-info-exclude-too-late
Specifically what you need to ignore a file is actually use the command git remove See git rm (http://www.kernel.org/pub/software/scm/git/docs/git-rm.html)
you test it by going
git rm --dry-run *.log
(if you say wanted to exclude all the log files)
this will output what would be excluded if you ran it.
then
you run it by going
git rm *.log
(or whatever filename path / expression you want to)
Navigate to the base directory of your git repo and execute the following command:
echo '\.*' > .gitignore
All dot files will be ignored, including that pesky .DS_Store if you're on a mac.