Skip to content

Instantly share code, notes, and snippets.

@dotysan
Last active April 21, 2025 15:17
Show Gist options
  • Save dotysan/c00d75744fd3a53efabd9752e5403687 to your computer and use it in GitHub Desktop.
Save dotysan/c00d75744fd3a53efabd9752e5403687 to your computer and use it in GitHub Desktop.
Copy a GitLab repo to GitHub, keeping only the default branch.
#! /usr/bin/env bash
#
# Copy a GitLab repo to GitHub, keeping only the default branch.
#
set -x
set -euo pipefail
GL_SITE=https://gitlab.flux.utah.edu
#GL_OWNER=emulab
#REPO=geni-lib
GL_OWNER=johnsond
REPO=openstack-build-ubuntu
main() {
if [[ ! -e "$REPO" ]]
then git clone "$GL_SITE/$GL_OWNER/$REPO.git"
fi
cd "$REPO"
local default_branch=$(git symbolic-ref --short HEAD)
local remote
get_remotes "$default_branch" |while read -r remote
do git branch --remotes --delete "$remote"
done
local me=$(gh_whoami)
gh repo create "$me/$REPO" --public
git remote add "$me" "[email protected]:$me/$REPO.git"
git push --set-upstream "$me"
# TODO: git push --tags "$me"
}
get_remotes() {
git branch --remotes --format='%(refname:short)' \
|grep -vE "^origin(|/$1)\$" ||:
}
gh_whoami() {
gh auth status |awk '
/Logged in to github\.com account/ {
print $7
}
'
}
main
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment