You can, in general, delete files and folders, but this has no effect on your subsequent git push
. Moreover, with git clone --mirror
, you get no checkout, because --mirror
implies --bare
which means there is no working tree.
The problem here is simple: Git does not push (or fetch/clone) files. Git pushes commits. (Normally the clone operation doesn't copy branches either—only the commits—but the --mirror
option changes that behavior, and the subsequent git push --mirror
pushes all two-or-more-level refs.)
Commits do contain files. But the files you see and work with in a non-bare repository are not in the repository. They are copies that were copied out of the repository. Modifying or removing these files has no effect on the repository, which consists mainly of commits. All commits are read-only: no commit can ever be changed, not even by Git itself. So the existing commits, that have existing snapshots, continue to have those snapshots for as long as those commits continue to exist.
What you can do instead is take a clone—any clone will do—and copy all of its commits to new and improved, but different, commits in a new clone. The new clone's commits will contain whatever they contain, since you just made them just now and that was completely under your control. This process, of filtering every commit from some existing repository to produce a new and different (incompatible) repository, should be done exactly once, since every time you do it, it's extremely disruptive: everyone must completely abandon the old repository and clone and use the new repository instead.
There is one program included in Git distributions for doing this: git filter-branch
. It is very difficult to use properly and is officially deprecated (a fancy word meaning "do not use this"). The new replacement, git filter-repo
, is not yet included in Git distributions, but it's definitely easier to use correctly. There is also something called The BFG (not related to the book/movie); see How to remove/delete a large file from commit history in the Git repository?
To be as clear as possible, the process would be:
git clone --mirror
as you're doing now, or git clone
without --mirror
followed by creating local branches for each remote-tracking name, if the filtering tool you have refuses to work on a bare repository;
- use one of the filtering methods to make a completely new repository;
git push
the new repository, perhaps also with --mirror
as you're doing now, after you're satisfied that the new repository looks correct.