TLDR; yes, you are going to remove the content you just removed, when you git pull from the VPS.
Let's analyze the situation here.
Every time I made a change locally, I pushed to the repository and
from the VPS where the site is (via SSH) I did git pull.
So this goes three ways, GitHub is your central repository, you develop locally, back it up remotely on GitHub for distribution, and pull from the VPS to deploy the website.
I realized that some folders previously placed in .gitignore
were
actually not being ignored.
This is a normal and well documented behavior. If the files were already added and committed prior their introduction in .gitignore
, they'll continue to be tracked. Also note that on the VPS, a git pull
command won't remove those file, but simply continue to ignore them.
Then I saw that it was possible to clear the git cache. I did it that
way and the next push actually ignored what I wanted it to ignore:
git rm -rf --cached .
git add .
git commit -am "cleaning git cache"
git push
You have now created a commit to specifically remove those files and stop tracking them, since they are added to the -gitignore
. From this point onwards, if you put a file which matches the ignore parameters in the working folder, it will be ignored. Not deleted, simply not mentioned for version control.
I have, for example, this in the file .gitignore
/storage
/storage/*/*
When I do git pull on the VPS, will the storage folder I have there
(which is full of useful files that should not be deleted at all) be
deleted?
One should point out that, since /storage
contains /storage/*/*
, the second line in your .gitignore
is redundant. But, alas. Back to the matter at hands: it doesn't matter on the content of .gitignore
. As we already know, those files will be ignored.
However, caveats are due:
- If you committed the removal of those files, then those files will be removed (it appears though you did this).
- If you clone the repository a-new on the VPS, that is if you purge your current website and
git clone
from GitHub, you'll probably never get the content of storage
this way.
- It seems to me that you don't want to put
storage
under version control, and yet the data is important to you. Back it up somewhere else.
The point is not .gitignore
in your case, but rather the fact that you explicitly committed the removal of those files.
Now, let me assume that the content of storage
is being updated only on the VPS and never committed nor pushed to GitHub. More caveats:
- git doesn't know about that content
- If you delete it, will be gone forever, from a git perspective
- If you are in this situation because the content was already committed once, and it never changes, and I am correct in both assumptions, then you should be able to find it in your repository history in a previous commit. But this goes a little bit out of scope for the answer.
After reading carefully the other answers, I'd like to link the docs (emphasis mine):
Remove files matching pathspec from the index, or from the working
tree and the index. git rm
will not remove a file from just your
working directory. (There is no option to remove a file only from the
working tree and yet keep it in the index; use /bin/rm if you want to
do that.)
And you queued that with recursive
, force
, and cached
:
Use this option to unstage and remove paths only from the index.
Working tree files, whether modified or not, will be left alone.
But, you override the up-to-date check with force
.