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 |
updating here, now, so I don't forget and let it drop off the radar again.
ps. pack
and unpack
in perl are onerous yet awesome.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a perl version, written against v5.14 for wide portability. Attempting to mimic the ui and git aesthetic. Currently only works for ssh remote repos in the scp style:
[user@]host:org/project.git
from: https://github.com/spazm/git-rename-remote-branch/blob/main/git-rename-remote-branch