Metadata, like pull requests and issues, are not part of a git repo. These features are provided by the platform that hosts your shared git repo. There are tools to migrate metadata from BitBucket, GitLab, Azure DevOps, GitHub Enterprise Server, and github.com. If tools don't exist to migrate the metadata from the platform you are using, your only option is to migrate only the git repo. To migrate a git repo without medatadata, follow the instructions below.
Familiarize yourself with the pre-migration documentation here.
If you are migrating a repo that uses LFS, make sure you have git-lfs installed.
- Clone the repo
- Checkout all remote branches locally.
for REF in $(git for-each-ref --format='%(refname)' refs/remotes/origin/ | grep -v main | grep -v master | grep -v HEAD); do
BRANCH_NAME=${REF#refs/remotes/origin/}
git branch --track ${BRANCH_NAME} ${REF}
done
- If the repo uses LFS, fetch all LFS objects
git lfs fetch origin --all
- Add new origin
git remote add github <new repo url>
- Push default branch
git push -u github $(git branch --show-current)
- Push all other branches
for REF in $(git for-each-ref --format='%(refname)' refs/heads); do
BRANCH_NAME=${REF#refs/heads/}
git push -u github ${BRANCH_NAME}
done
- Push all tags
git push github --tags
Familiarize yourself with the post migration documentation here.
If you want to script all this, you might consider automating the new repo creation on GitHub using the REST API. https://docs.github.com/en/rest/repos/repos#create-an-organization-repository