-2

I have added a folder in my .gitignore file. But when I pushed to the repo it was still being pushed. my folder structure is:

UI/node_modules

In the .gitignore I have added the following:

/UI/node_modules
/UI/bin

Is there anything I am doing wrong? gitignore file sits at the same level as the UI folder

Sole
  • 3,100
  • 14
  • 58
  • 112
  • Already versioned files will not be ignored after being placed in `.gitignore`. Please read [ask] and try researching the issue. – CodeCaster May 08 '19 at 14:56
  • 1
    @OznOg: the leading slash is OK, but not required here. If you list, e.g., `*.o` or `somefile` in a `.gitignore` file, that means *every* `*.o` or `somefile`: `erin.o`, `fred/fred.o`, `gina/somefile`, and so on. If you list `/*.o` that means only files in the *current* directory: `erin.o` is excluded but not `fred/fred.o`. However, as soon as you have a slash *within* the path, such as `UI/bin`, the leading slash is implied anyway: `UI/bin` and `/UI/bin` have the same meaning in a `.gitignore`. This is not true for *trailing* slash, so `UI/` includes all `UI/` files but also `fred/UI/` files. – torek May 08 '19 at 15:29
  • 1
    On the other hand, `/UI/` means only `UI/` files in the directory containing that `.gitignore` file. – torek May 08 '19 at 15:30

1 Answers1

-2

You have got to delete the folder from the online repository. To do so, you can Cut and Paste the folder somewhere else, push everything, paste back the folder and push again with the folder listed in .gitignore file.

  • That's not how any of this works. `git push` operates on _commits_, not files. Unless you commit the removal of the content pushing won't do anything. And Git's ignore system only applies to untracked content, so again, you must _commit_ the removal. The easiest way to do this is to `git rm --cached` the content (assuming OP still wants it locally), not to drag it around the filesystem. – ChrisGPT was on strike May 08 '19 at 16:36
  • Actually that's what I mean, when I said push, I meant implicitly (add, commit and push everything). But yeah you're right, I didn't know about git rm --cached, thanks. – Kais Ben Daamech May 08 '19 at 17:26