rtyley / bfg-repo-cleaner

Removes large or troublesome blobs like git-filter-branch does, but faster. And written in Scala
https://rtyley.github.io/bfg-repo-cleaner/
GNU General Public License v3.0
10.84k stars 535 forks source link

Working with BFG on a local .git #446

Open ityulkanov opened 2 years ago

ityulkanov commented 2 years ago

Before the push to GitHub, I need to clean up some files that I've pushed to git sometime ago. I've stumbled on bfg, but can't figure out the correct way to do --mirror with local repo, since I only have a .git folder. I've tried running bfg being inside of a project file on a .git folder level, but that doesn't seem to work. Should I upload to GitHub first, and then do --mirror or there is a more elegant way to invoke bfg on a local repo? I'm sure I'm not the only one with the same question, but quick issues search doesn't yield any results.

jms1voalte commented 2 years ago

If a repo is cloned "normally" in $HOME/git/xyzzy-full/, you should be able to do this:

cd $HOME/git
git clone --mirror xyzzy-full xyzzy-bare

The xyzzy-bare/ directory will be a "bare" copy of whatever repo exists in the xyzzy-full/ directory.

The reverse is also true. If you have a "bare" repo in $HOME/git/xyzzy-bare/, you can do this:

cd $HOME/git
git clone xyzzy-bare xyzzy-full

The xyzzy-full/ directory will be a "normal" clone of whatever repo exists in the xyzzy-bare/ directory. It'll be a full working directory, you'll be able to git checkout different branches/tags/etc.

In both cases, running git remote -v in the directory should show you an origin remote pointing to whatever local directory the repo was cloned from. Commands line git push and git fetch will "work" as if that other directory were a "server" (like GitHub).

Regarding using BFG to clean upn existing repo, you may want to try something like this:

Something else I ran into ... if you used --convert-to-git-lfs, you'll need to also run git lfs install within the bare repo directory before running git push, otherwise it won't know to upload the now-LFS-based files, to LFS.