.gitignore not ignoring folder

32.2k Views Asked by At

I have a project in Laravel and I have forum in public directory which I don't want to push it to repository, so I write in .gitignore:

### Laravel ###
vendor/
node_modules/

# Laravel 5 & Lumen specific
bootstrap/cache/
.env.*.php
.env.php
.env

# SMF
public/forum/

# Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer
.rocketeer/

However, the entry still appears in Git status
Here is my tree with it:
+...
+ public
++ forum
+++...
+...
Where is the problem?

Directory structure enter image description here

Git status enter image description here

5

There are 5 best solutions below

2
On BEST ANSWER

The problem is that this folder is already in your index (you committed it at an earlier moment). Changes to files in the index will always be in "git status". Only new files in that folder will be ignored.

To fix it. See my answer on https://stackoverflow.com/a/38304114/2274140

0
On

Do the following to trigger the gitignore:

  1. Commit all your pending changes in the repository which you want to fix and push that.

  2. Remove everything from the git index in order to refresh your git repository. This is safe. Use this command:

    git rm -r --cached .
    
  3. Add everything back into the repo, which can be done using this command:

    git add .
    
  4. Commit these changes, using this command:

    git commit -m "Gitignore issue fixed"
    
0
On

In .gitignore add

public/forum

Run

git rm --cached -r public/forum
0
On

In my case

  • git was not ignoring build/ directory for a Java project when I had added build/ in my .gitignore
  • i tried changing it to build/* without luck

finally removing the slash / by keeping just build in .gitignore worked


PS: my build directory was never checked in (git added), just that it was lying around and git kept reporting it under Untracked files

0
On

In case anyone else has this problem and does, like me, want to keep those files there, I simply:

  1. Cut / paste all the files into a different folder outside of my repo.
  2. Committed the changes to git (aka committed the deletions)
  3. Pasted the files back in

Good to go, and the files no longer reappeared. Hopefully your case will be similar.