My question might seem a bit strange since what I want can usually be accomplished by simply deleting the repository and creating a new one. Here's the reason why I still need to keep the repository: The history of my repository is actually the most valuable part of the repository. I generate an entire repository with all the data. The repository is hosted on github and I want to update the repository there to look exactly like the local repository (identical history).
The only way I have found to do this so far has been to delete and recreate the repository on github before pushing to it. Otherwise all of the old commits would still be there, effectively altering the historical information of the repository. Of course it is fairly easy to recrate a repository on github but along with the repository all watchers, wiki info etc. are lost and I'd like to prevent that.
I've posted here instead of github since I think that this question is rather related to Git than to the hosting service.
Any thoughts?
To entirely remove unwanted files from a repository's history you can use either the git filter-repo tool or the BFG Repo-Cleaner open source tool. The git filter-repo tool and the BFG Repo-Cleaner rewrite your repository's history, which changes the SHAs for existing commits that you alter and any dependent commits.
3. Using the git rm –cached Command. We've mentioned that git rm FILE will remove files from the index and local working tree by default. However, the git rm command provides the –cached option to allow us only to remove files from the repository's index and keep the local file untouched.
Run git --git-dir . gc --aggressive --prune=now locally. Completely delete the git repo from your Gitlab server.
A forced push such as git push origin +master
should help. All remote changes will be lost.
Step 1: Delete all remote branches:
git fetch
git branch -r
For each line of output (they should look like origin/master
, origin/branch1
, ...) add it to a git push
line like this:
git push origin :master :branch1 ...
Step 2: Push your local branches
git push origin master branch1 ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With