Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git ignoring .gitignore file in parent directory

Tags:

git

gitignore

I have a structure like this:

projects/
    .gitignore
    foo/
        some_file
    bar/
        another_file

foo, bar, and projects are git projects. In .gitignore I have * (actually I tried loads of things), however when I run git status inside projects/foo it still tells me to add some_file. If I'm reading the .gitignore documentation correctly it says Git should look in all parent folders for .gitignore files and use those. However it seems to totally ignore the one in .gitignore. What is going on here?

I've tried git check-ignore and it just behaves as if the .gitignore did not exist.

To reproduce:

/ $ cd /tmp
/tmp $ mkdir projects
/tmp $ cd projects
/tmp/projects $ echo "*" > .gitignore
/tmp/projects $ git init
Initialized empty Git repository in /private/tmp/projects/.git/
/tmp/projects $ mkdir foo
/tmp/projects $ cd foo
/tmp/projects/foo $ git init
Initialized empty Git repository in /private/tmp/projects/foo/.git/
/tmp/projects/foo $ touch some_file
/tmp/projects/foo $ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    some_file

nothing added to commit but untracked files present (use "git add" to track)
like image 685
Timmmm Avatar asked Dec 11 '17 15:12

Timmmm


1 Answers

Git only use rules in .gitignore file in the currect repository. You may want to symlink or hard link the .gitignore file from parent directory to all subdirectories if you want it to apply to all sub repositories.

like image 125
iBug Avatar answered Oct 20 '22 00:10

iBug