In the past I've used git filter-branch
to remove files from my Git history. Following that, I can do a force push to update the remote repository. For example, removing all HTML files from the local repository and then rewriting the remote to reflect the change:
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch -r \*.html' --prune-empty -- --all
git push origin --force --all
This works perfectly fine. But seeing as filter-branch
is extremely slow and has been deprecated for a while, I'd like to do this with git-filter-repo
instead. So far, this seems to be the equivalent command:
git-filter-repo --force --path-glob *.html --invert-paths
This first step appears to work. My issue is when I attempt a force push afterwards, I see my remotes have been lost.
git push origin --force --all
Output:
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
The filter-repo command appears to have removed my remote URLs when I check git remote -v
. Adding back the remote manually puts me down a rabbit hole of other settings be invalid.
Why does git-filter-repo
remove my remote? And how can I rewrite remote's history using git-filter-repo
like I'm able to with git filter-branch
?
Why does git-filter-repo remove my remote?
The documentation explains their reasoning, in the section titled INTERNALS:
- We don’t want users accidentally pushing back to the original repo, as discussed in DISCUSSION. It also reminds users that since history has been rewritten, this repo is no longer compatible with the original. Finally, another minor benefit is this allows users to push with the
--mirror
option to their new home without accidentally sending remote tracking branches.
And how can I rewrite remote's history using git-filter-repo like I'm able to with git filter-branch?
Just use git remote add
to put origin
back, or—since step 3 in the command sequence is git remote rm origin
—just rename origin
to some other name first. If you do that, though, note step 2.
You said:
Adding back the remote manually puts me down a rabbit hole of other settings be invalid.
You'll need to go into more detail here, obviously.