shutdown-protocol.sh
source link: https://gist.github.com/lf94/d8e7d11a24ddad8315d28741e6d6bf2e
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
The script I made to do this is very rudimentary, use at your own risk.
Clone all your repositories into a directory:
mkdir GitHubProjects;
cd GitHubProjects;
CNTX={users|orgs}; NAME={username|orgname}; PAGE=1
curl "https://api.github.com/$CNTX/$NAME/repos?page=$PAGE&per_page=100" |
grep -e 'clone_url*' |
cut -d \" -f 4 |
xargs -L1 git clone
Make a duplicate of all the repositories using cp -r
to scrub them.
cd .. && cp -r GitHubProjects GitHubProjects_Scrub
Create a message you'll leave in a file and run the following on the copy of repositories (./shutdown-protocol.sh GitHubProjects_Scrub NewREADME.md
).
#!/bin/sh
#
# Usage: ./shutdown-protocol.sh <directory-of-projects> <message-to-leave>
#
# <directory-of-projects> is a copy of a directory with all your GitHub
# projects.
# <message-to-leave> is a file that will be left in a README.md
#
# This script deletes all sources except the .git file, git rebases to the
# beginning and force pushes the new content. It will delete all remote
# branches.
#
#
cwd="$PWD"
cleanup() {
echo "$1"
cd "$1"
git fetch --all
remotes=$(git branch --remotes)
echo "$remotes" | sed 's/origin\///' | xargs git push -f -d origin
echo "$remotes" | xargs git branch -r -D
cp .git/config gitconfig
sed -i -e 's/https:\/\/github.com\//[email protected]:/' gitconfig
find . ! -name 'gitconfig' -exec rm -rf {} +
git init
mv gitconfig .git/config
cp "$cwd"/README.md README.md
git add README.md
git commit -m "Cleared previous history"
git push -f origin main
git push -f origin master
git push -f origin main:master
git push -f origin master:main
}
for d in "$1"/*;
do
cleanup "$d" "$2"
done
What are you trying to achieve with this script? The commit data will not be wiped away but still be available on the servers at the companies disposal.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK