Created
June 13, 2020 17:58
-
-
Save frioux/6c259c63dda705f9ef9d030ddb880347 to your computer and use it in GitHub Desktop.
You can run this (using https://github.com/ingydotnet/git-hub) to rename all default branches from master to main; run from a fresh, empty repo or the repo you run it from will get all bloated with garbage refs.
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 | |
set -e | |
for r in $(git hub repos -r --all); do | |
json=$(git hub repo "$r" --json) | |
# ignore forks | |
if [ -n "$(echo "$json" | jq -r '.["source/full_name"]+""')" ]; then | |
echo "skipping $r; fork" | |
continue | |
fi | |
archived=$(git hub repo-get $r archived) | |
if [ "$archived" = "true" ]; then | |
echo "skipping $r; archived" | |
continue | |
fi | |
# find out if HEAD is master: | |
br=$(git hub repo-get $r default_branch) | |
if [ "$br" != master ]; then | |
echo "skipping $r; default_branch=$br" | |
continue | |
fi | |
echo "fetching $r to rename branch..." | |
git fetch -q git@github.com:$r | |
git push git@github.com:$r FETCH_HEAD:refs/heads/main | |
git hub repo-edit $r default_branch main | |
git push git@github.com:$r --delete master | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updating here, now, so I don't forget and let it drop off the radar again.
ps.
pack
andunpack
in perl are onerous yet awesome.