2

I have seen similar questions but this situation is unique.

Locally, I have an ignored folder in my repository, but somehow it got onto Github, 2 months ago apparently even though it has been ignored long before that and is still ignored and I have edited the repository both inside and outside of the ignored folder and pushed to Github many times in the past 2 months.

So anyway, how do I go about removing the directory from Github without removing it locally? You would think just "push origin" would work, but apparently not.

Moss
  • 3,695
  • 6
  • 40
  • 60
  • If it randomly got "un-ignored" then a quick guess is that your ignore pattern isn't actually for the folder; when the folder gained a file which doesn't match your ignore pattern, it got included in the repo. Have you checked that ignore pattern and also a simple check is to compare the files in there on GIthub with your local ones. (A useful addition might be your .gitignore file). – Luke Briggs Feb 02 '17 at 01:10
  • So this is a duplicate question after all. I guess I didn't find the previous question because I was just searching for how to delete a folder or directory, not a file. – Moss Feb 02 '17 at 08:18
  • My project is ignoring the folder like `/folder/`. Locally, it knows it is ignored. If you add something to the ignore file will it not automatically remove it from the remote repository when you push? If not, then I guess that's what happened, but I swear I did it way more than two months ago. – Moss Feb 02 '17 at 08:22

1 Answers1

4

Just because you never added the folder doesn't mean that someone else on your team didn't accidentally did so. In any case, you don't have to delete the folder locally to ignore it. You can simply do:

git rm -r --cached folder/
git commit -m 'removed old folder'
git push origin master   # or whatever branch you are using

Next you can add the folder to a .gitignore file in the folder containing the folder you want to ignore. Add this line:

folder/

Now the folder is removed from GitHub and also is being ignored locally. Note that the folder is still part of the remote branch's history. If you want to sterilize that as well, it will take a bit more work.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • OK, now I understand what --cached does. The instructions say it removes from the index but I didn't know what that meant. I thought this would delete the file locally too. Thanks. – Moss Feb 02 '17 at 08:08