Let's start with cloning the source repo banana
git clone https://github.com/lihaoml/banana.git beanex
Now let's remove the origin in the cloned directory beanex:
git remote rm origin
Verify that origin has been removed:
lihao@mAusPro:~/workspace/go/src/beanex$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[branch "master"]
We will then use to remove the directories that we do not want to keep in bean
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch -r telegram shake main html tools viewer' -- --all
Then remove the empty commits
git filter-branch -f --prune-empty
we can delete everything and restore what you want []
# for unix
$ git checkout master
$ git ls-files > keep-these.txt
$ git filter-branch --force --index-filter \
"git rm --ignore-unmatch --cached -qr . ; \
cat $PWD/keep-these.txt | tr '\n' '\0' | xargs -d '\0' git reset -q \$GIT_COMMIT --" \
--prune-empty --tag-name-filter cat -- --all
# for macOS
$ git checkout master
$ git ls-files > keep-these.txt
$ git filter-branch --force --index-filter \
"git rm --ignore-unmatch --cached -qr . ; \
cat $PWD/keep-these.txt | tr '\n' '\0' | xargs -0 git reset -q \$GIT_COMMIT --" \
--prune-empty --tag-name-filter cat -- --all
To cleanup
$ rm -rf .git/refs/original/
$ git reflog expire --expire=now --all
$ git gc --prune=now
# optional extra gc. Slow and may not further-reduce the repo size
$ git gc --aggressive --prune=now