I\'m trying to create a new git repository from existing folder. I\'ve created a .gitignore
file in the root of the folder. But if I say
git add
I've had issues with .gitignore also. I checked out the linked answers listed about, which fixed half the issue.
What really got gitignore working full for me was adding a comment on the first line of the file. Git wasn't parsing the exclude situated on the first line.
Cheers
You could have created a UTF-8 encoded text file. Try saving it as ANSI encoded. In git bash, you can verify by using vi -b.
Probably your exclude file mask is inacurate.
I'm using git version 1.7.12.3 on MacOSX and the first line of .gitignore is also not taken into account. Just add a comment as first line.
Are your files already tracked? .gitignore only silences comments about untracked files, but won't stop a tracked file from being tracked.
A trick I faced on windows is that using echo
(as per Jakub Narębski answer) you have to be careful with spaces.
As you can see below any space before the redirection operator does have an effect on the actual ignore.
C:\test>dir /B
TOBEIGNORED
C:\test>echo TOBEIGNORED > .gitignore
C:\test>git status
[...]
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# TOBEIGNORED
C:\test>echo TOBEIGNORED> .gitignore
C:\test>git status
[...]
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
nothing added to commit but untracked files present (use "git add" to track)