Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@postmodern
Last active December 7, 2021 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save postmodern/00b117403fec2a2d7c1fc4f35785cf00 to your computer and use it in GitHub Desktop.
Save postmodern/00b117403fec2a2d7c1fc4f35785cf00 to your computer and use it in GitHub Desktop.
Boilerplate script for automating git-filter-repo
#!/usr/bin/env bash
set -e
shopt -s globstar
github_user="FIXME"
orig_repo="FIXME"
new_repo="FIXME"
branch="main"
files=(
FIXME
)
args=()
for path in "${files[@]}"; do
args+=(--path "$path")
done
git clone "https://github.com/${github_user}/${orig_repo}.git" "$new_repo"
cd "$new_repo"/
git checkout "$branch"
git filter-repo --force "${args[@]}" --tag-rename '':"${orig_repo}-"
git branch -D main || true
git branch -m main
git tag "$orig_repo"
git remote add origin "git@github.com:${github_user}/${new_repo}.git"
@postmodern
Copy link
Author

and if you want to get a list of every file that ever existed in the git repo, and grep through them for the file/dir names you want to save:

git log --pretty=format:" " --name-only | sort -u | egrep "(name1|name2|...)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment