Last active
April 19, 2017 08:16
-
-
Save nickbdyer/7203b4f6854e29c28f0d569a7f415b04 to your computer and use it in GitHub Desktop.
Anonymise Script for London Applicants
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# $1 - new identifier to use | |
# $2 - repo to clone | |
IDENTIFIER=$1 | |
SOURCE_REPO=$2 | |
DEST_DIR=`pwd` | |
# Step 1 - Make temporary directory | |
SOURCE_GIT_DIR=`mktemp -d` | |
echo $SOURCE_GIT_DIR | |
cd $SOURCE_GIT_DIR | |
git clone --bare $SOURCE_REPO $SOURCE_GIT_DIR | |
BRANCHES=`git branch --list | awk '{print $2}'` | |
# Step 2 - rename branches | |
for branch in $BRANCHES; do | |
NEW_BRANCH=$IDENTIFIER-$branch | |
git branch -m $branch $NEW_BRANCH | |
done | |
# Step 3 - change commit info | |
for branch in $BRANCHES; do | |
# -f so multiple operations can be performed at once | |
git filter-branch -f --env-filter ' | |
export GIT_AUTHOR_NAME="Anonymous" | |
export GIT_AUTHOR_EMAIL="anon@example.com" | |
export GIT_COMMITTER_NAME="Captain Commit" | |
export GIT_COMMITTER_EMAIL="anon@commit.com"' $NEW_BRANCH | |
done | |
# Step 4 - Remove originals | |
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d | |
# Step 5 - Create remote in the original repo | |
# TODO: use --no-tags because this script won't have done any work on tags? | |
cd $DEST_DIR | |
git remote add -f --no-tags $IDENTIFIER $SOURCE_GIT_DIR | |
# Step 6 - checkout branch | |
for branch in $BRANCHES; do | |
git checkout $IDENTIFIER-$branch | |
done | |
# Step 7 - Delete temporary directory | |
rm -rf $TEMP | |
# Step 8 - Delete remote branch | |
git remote rm $IDENTIFIER | |
# Step 9 - Push to origin | |
git push | |
# Step 10 - Delete local branch | |
git checkout master | |
git branch -D $IDENTIFIER-$branch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment