Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export all my GitHub account content in one action, delete the account and then import the exported content into a new GitHub account?

Tags:

git

github

I think about creating a new GitHub account, free from any previous communal collaboration and yet before I delete my account I want to export all of my repositories in one action instead download their zip files one by one.

How to export all my GitHub account content in one action, delete the account and then import the exported content into a new GitHub account?
I'd assume that some Git algorithm exists and implementable.


1 Answers

I'd assume that some Git algorithm exists and implementable.

Git knows nothing about GitHub and has no way to discover remote repositories.

Your best option is probably going to be the github cli. You can get a list of all your repositories using the gh repo list command. Something like this would let you clone all of your repositories into the current directory:

gh repo list -L1000 --json sshUrl | jq -r '.[]|.sshUrl' | while read url; do
    git clone --mirror $url
done

(The -L1000 there is because gh repo list will only display information about 30 repositories by default. If you have more than 1000 repositories, increase the number as appropriate.)

You could upload all your repositories to a new account by iterating over the cloned repositories and using the gh command to create a new repository on GitHub, and then git push the content:

for repo in *; do
  git -C $repo remote set-url origin [email protected]:mynewuser/$repo
  git -C $repo push --all origin
done

This is all untested, but hopefully gives you an idea of where to start.

like image 188
larsks Avatar answered Nov 07 '25 06:11

larsks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!