windows - untracked - gitignore folder and subfolders




Ignoring directories in Git repos on Windows (12)

How can I ignore directories or folders in Git using msysgit on Windows?


Also in your \.git\info projects directory there is an exclude file that is effectively the same thing as .gitignore (I think). You can add files and directories to ignore in that.


By default windows explorer will display .gitignore when in-fact the file name is .gitignore.txt

Git will not use .gitignore.txt

And you can't rename the file to .gitignore because explorer thinks its a file of type gitignore with no name.

Non command line solution:

You can rename a file to ".gitignore." and it will create ".gitignore"

I assume the problem is that your working tree is like:

a-cache/foo
a-cache/index.html
b-cache/bar
b-cache/foo
b-cache/index.html
.gitignore

... with the .gitignore you describe. This will give you git status output like:

$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   .gitignore
#   a-cache/
#   b-cache/

... if the index.html files have not yet been added to the repository. (git sees that there are unignored files in the cache directories, but only reports the directories.) To fix this, make sure that you have added and committed the index.html files:

git add *cache/index.html
git commit -m "Adding index.html files to the cache directories"

... and your git status will then look like:

$ git status
# On branch master
# 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)

(Obviously you do want to commit .gitignore as well, I was just being lazy with this test case.)


I had similar issues, I work on a windows tool chain with a shared repo with linux guys, they happlily create files with the same [except for case] names in a given folder.

The effect is that I can clone the repo and immediatly have dozens of 'modified' files that if I checked in would create havoc.

I have windows set to case sensitive and git to not ignore case but it still fails (in the win32 api calls apparently).

If I gitignore the files then I have to remember to not track the .gitignore file.

But I found a good answer here http://archive.robwilkerson.org/2010/03/02/git-tip-ignore-changes-to-tracked-files/index.html

Chris


I've had some problems getting git to pickup the .gitignore file on Windows. The $GIT_DIR/info/exclude file always seems to work though. The downside of this approach, however, is that the files in the $GIT_DIR directory are not included in the check-in, and therefore not shared.

( p.s. $GIT_DIR is usually the hidden folder named .git )


If you want to maintain a folder and not the files inside it, just put a ".gitignore" file in the folder with "*" as content. This file will ignore all content from repository. But .gitignore will be include in your repo.

$ git add path/to/folder/.gitignore

If you add empty folder, you receive this message (.gitignore is 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

It seems that for ignoring files and directories there are two main ways:

  1. .gitignore

    • Placing .gitignore file into the root of your repo besides .git folder (in Windows make sure you see the true file extension and then make .gitignore. (with the point at the end to make empty file extension) )
    • Making global configuration ~/.gitignore_global and running git config --global core.excludesfile ~/.gitignore_global to add this to your git config

    note: files tracked before can be untracked by running git rm --cached filename

  2. Repo 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 commited, so are not seen by other users more info here

[updated] To make exceptions in list of ignored files, see this question.


Just in case you need to exclude sub folders you can use the ** wildcard to exclude any level of sub directory.

**/build/output/Debug/

On windows and Mac, if you want to ignore a folder named Flower_Data_Folder in the current directory, you can do:

echo Flower_Data_Folder >> .gitignore

If its a file named data.txt

echo data.txt >> .gitignore

if its a path like "Data/passwords.txt"

echo "Data/passwords.txt" >> .gitignore.


To ignore an entire directory in git, the easiest way is to include a .gitignore file within the target directory which simply contains "*"

An illustrative example,

Example System

/root/
    .gitignore
    /dirA/
        someFile1.txt
        someFile2.txt
    /dirB/
        .gitignore
        someFile3.txt
        someFile4.txt

Goal

  • ignore the contents of /dirB/

Top Level .gitignore (/root/.gitignore)

  • This is where your standard gitignore info goes

Ignored Directory .gitignore (/root/dirB.gitignore)

  • This file just reads as '*' and the directory is ignored completely, itself and all files!

and it's that simple :)


You can create the ".gitignore" file with the contents:

*
!.gitignore

It works for me and simples.


to instruct GIT to ignore certain files or folders, you have to create .gitignore file.

but in windows explorer you have to provide a name for the file, you just cannot create file with just extension, the trick is that create a empty text file and go to command prompt and change the name of the file to .gitignore

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 *.txt

hope it answers you question





msysgit