1

I am having trouble with my .gitignore. I have a directory tree like so:

/djangoproject
    venv
        bin
            startgunicorn.sh
        djo
    www
        static
        analytics
    .git
        .gitignore

My .gitignore reads:

../www/analytics
../venv/bin
../venv/build
../venv/include
../venv/lib
../venv/local
*.pyc

When I

git add ../* or git add -A

git push

I don't want startgunicorn.sh or my analytics dir to be pushed, but I do want djo and static to be. That's not happening—my gunicorn.sh file keeps changing to the local machine's. Where is my error?

mh00h
  • 1,824
  • 3
  • 25
  • 45

2 Answers2

4

I've never seen anyone place a .gitignore file in the .git subdirectory before. As far as I know, it should be in the root if you wish to apply the rules to the entire repository.

GitHub say the following:

Note that you can create a .gitignore in any subpath to have its rules applied at that path. Sometimes an empty .gitignore file is used as a placeholder for an empty path, for example to force git to generate a log/ path for your development environment to use.

Going by that logic, all those rules will all be applied from the .git folder downwards. I can see what you're trying to do, but I've never seen it done before that way.

I would put the .gitignore in the root of the repository, and have it look like this:

www/analytics
venv/bin
venv/build
venv/include
venv/lib
venv/local
*.pyc

I'd expect that to do the right thing.

In addition, it is worth bearing this in mind:

Note that git will not ignore a file that was already tracked before a rule was added to this file to ignore it. In such a case the file must be un-tracked, usually with git rm --cached filename

You will possibly need to do that, if you've added older versions of those files you wish to ignore.

Mark Embling
  • 12,605
  • 8
  • 39
  • 53
  • 1
    Late to the party but for those following along at home, starting with git 1.8.2, `**` can be used to ignore all files in a folder up to infinite depth. E.g., `venv/**`. See [here](http://stackoverflow.com/questions/1470572/gitignore-ignore-any-bin-directory). – franklin Oct 25 '15 at 15:55
0

Maybe try placing .gitignore in main project's directory (where .git directory is) and removing "../" at beginings of paths.

If that doesn't help try adding

venv/bin/* 

to your .gitignore.