I know similar questions have been asked multiple times, but I cannot get it to work for my case.
Where I am: I have a local repo that I push to a live server, that included a /content folder and its subfolders. During production that was okay, since I could make changes to /content and just push them. But since this is a website using a CMS all changes to /content will now be produced remotely.
Where I want to be: I now want to 'detach' /content and its subfolders from the code base, so that I can delete the hefty /content folder locally without it being deleted on the live server. That way I still would be able to make changes in the code and push them to the server, while people are able to use the CMS to create files and changes in the /content folder.
So what I did so far:
- added the folder to .gitignore:
/content/
- removed the folder from the index:
git rm -r --cached content/*
- tried to set assume-unchanged so that on push, the files in /content would not be deleted from the live server:
git update-index --skip-worktree
When I do this, I of course get a:
fatal: Unable to mark file
Since the files are in .gitignore, and they need to stay there, such that the folder will be ignored in the future. So what do I do?
Updated to reflect correction from OP, that the updates had been done on the local clone rather than the server, and that the server is a bare repo with a hook that updates the working folder via
checkout -f
The index flags (
skip-worktree
orassume-unchanged
) are not the solution to the problem, but your understanding of why (that it has anything to do with.gitignore
) is not correct either. Rather, those flags are set on the file's entry in the index; you can't set the flag on those files because you removed the files from the index.You clarified that the three steps you mention (create
.gitignore
, runrm --cached
, attempt to set index flags) were done on the local clone. So the next question would be how to sync this up with the server, without deleting the server'scontent
directory.The index, like the worktree, is local. So the server isn't yet aware that you've done anything. The next time you do a commit and push it, you'll need to take steps to properly update the server (or else the content directory will be lost). I recommend doing this now, so that you don't have additional changes to juggle at the same time (and so that you don't forget to do the extra steps).
You'll need to jump back and forth between the local and the server, so I'd go ahead and open a shell on each.
On the server, you need to prevent the worktree from being automatically updated by the upcoming push. Because your server-side repo is bare and the update occurs by way of a hook, disable the hook. (Either move the post-receive script out of the hooks directory, or edit it and comment out the lines that checkout the changes.)
Now locally you need to stage the
.gitignore
file and commit the changes (which will include the removal (from the index) of thecontent
directory), and push:Now on the server you need to sync up the work tree, and re-enable the hook. Since the only change (other than suppressing the
content
folder) was the .gitignore filewill sync things back up. Then undo whatever you did to disable the hook.