DEV Community

Mike Rogers ✈️
Mike Rogers ✈️

Posted on • Updated on

How To Setup A Secondary Archive Account On GitHub

If you're anything like me, you probably have a GitHub account where you've collected a lot of repositories over time, most of which you probably won't update any time soon.

You probably also want to make you sure GitHub profile is an amazing example of your best work, where a potential employer isn't going to be distracted by an old irrelevant project.

To solve this, I setup a GitHub Organisation specifically for my projects which I probably won't maintain (it's @mikerogers0-youtube if you want to see it in action). It's nothing fancy, just an account where I can store stuff which is a bit out of the way.

It was really cool to do, so I wanted to share how I done it encase anyone else wanted to do the same :D

Automating It With Ruby

Manually moving the repos felt laborious, so I wrote a script in Ruby to use the GitHub API semi-automate it:

# Run: gem install octokit
require 'octokit'

## Generate a token at:
# Make sure it has a scope of:
# - Full control of private repositories 
# Put the token in here:

## The account name you're going to transfer things off to:
NEW_ACCOUNT_NAME = "MikeRogers0-YouTube"

# Connect to GitHub
client = PERSONAL_ACCESS_TOKEN, auto_paginate: true)

# Load all the repos in the users account
repositories = client.repositories(client.user.login)

# Filter the list of repos you're going to transfer! do |repository|
  ## Options include:
  # repository.fork?
  # repository.private?'Sample')

# Tell us what repos we're about to move
puts "You're going to transfer:"
puts repositories.collect(&:full_name)

# This stopped me accidentally breaking everything, remove the
# "return" line to actually perform the transfers.
puts 'Remove the next line to perform the change:'

# Start transferring the accounts to the new account
repositories.each do |repository|
  client.transfer_repository(repository.full_name, NEW_ACCOUNT_NAME, {
    accept: Octokit::Preview::PREVIEW_TYPES[:transfer_repository]
Enter fullscreen mode Exit fullscreen mode

It took me a few tries to get my filters about right, but once I was happy with the repositories I was transferring I removed the return line & let it do the transfer.

I got a bunch of emails confirming the repos had been moved, but overall it took a few seconds to transfer everything.

What happened next?

After I transferred everything, I was worried I'd have to update a bunch of old links online, but I noticed GitHub made 301 redirects from my old projects to the new ones. This was awesome!

I feel really positive about having a digital clean out, I'd totally encourage everyone to consider it :D

Latest comments (0)