Ignoring directories in Git repositories on Windows
How can I ignore directories or folders in Git using msysgit on Windows?
Create a file named
.gitignore in your project's directory. Ignore directories by entering the directory name into the file (with a slash appended):
More information is here.
Read more... Read less...
By default, Windows Explorer will display
.gitignore when in fact the file name is
Git will not use
And you can't rename the file to
.gitignore, because Windows Explorer thinks it's a file of type gitignore without a name.
Non command line solution:
You can rename a file to ".gitignore.", and it will create ".gitignore"
It seems that for ignoring files and directories there are two main ways:
.gitignorefile into the root of your repository besides the
.gitfolder (in Windows, make sure you see the true file extension and then make
.gitignore.(with the point at the end to make an empty file extension))
- Making the global configuration
git config --global core.excludesfile ~/.gitignore_globalto add this to your Git configuration
Note: files tracked before can be untracked by running
git rm --cached filename
Repository exclude - For local files that do not need to be shared, you just add the file pattern or directory to the file
.git/info/exclude. Theses rules are not committed, so they are not seen by other users. More information is here.
To make exceptions in the list of ignored files, see this question.
To instruct Git to ignore certain files or folders, you have to create
But in Windows Explorer you have to provide a name for the file. You just cannot create file with just an extension. The trick is that create a empty text file and go to command prompt and change the name of the file to
ren "New Text Document.txt" .gitignore
Now open the file with your favorite text editor and add the file/folder names you wish you ignore. You can also use wildcards like this:
If you want to maintain a folder and not the files inside it, just put a ".gitignore" file in the folder with "*" as the content. This file will make Git ignore all content from the repository. But
.gitignore will be included in your repository.
$ git add path/to/folder/.gitignore
If you add an empty folder, you receive this message (.gitignore is a hidden file)
The following paths are ignored by one of your .gitignore files: path/to/folder/.gitignore Use -f if you really want to add them. fatal: no files added
So, use "-f" to force add:
$ git add path/to/folder/.gitignore -f