For the past couple months, I’ve been studying. As a side effect, my GitHub account was cluttered with code that is experimental. I didn’t exactly want to trash the experimental code. I wanted to keep my code but also not specifically keep it under my profile.
The solution I found was to create an organization and transfer my desired repositories there. I thought this was a great solution, there was just one little detail I was missing: the current GitHub API does not support repository ownership transfer. Which meant I would have to go to each repository, click on “Settings”, click on “Transfer”, fill in the “Repository Name” and then put the “Destination User”. A lot of steps for someone looking to move over 250 repositories.
The first thing that came to my mind was to use Selenium to automate this task. But my lack of exposure with the technology made me think a bit outside the box. One of the things I learned these past months was capybara. Capybara is used alongside Rspec, extending the test suite DSL. It mimics user interaction with the browser and comes with a Selenium driver out of the box.
In other words, you can create a bot to go to the browser, fill up forms and submit it. This is exactly what I was looking for. As I stated before, Capybara uses Rspec, so my code would actually have to be wrapped inside a test.
- You need to disable two-factor authentication on GitHub, and after the script finishes running set it back on.
- It does not transfer private repositories.
- You need Mozilla’s geckodriver installed. If you use macOS, you can use
brewto install it.
This was developed as a hack. Use at your own risk. You can download it at gabidavila/github-move-repositories. As of now this code gets all public repositories, unless the variable
ONLY_FORKS is set to
TRUE, and moves to a destination user. Do not push your
.env file.If you want to move only specific repositories, you will need to edit the code yourself. For more information the README.md of this project is kept up to date.
Contributions are welcome if you feel you can help improve the tool. For example: add options of which repositories to move.