13 January 2009

Renaming a GitHub Account and Forked Repository

Today I finally bit the bullet and renamed the DealBase GitHub account and repository because it was previously named after an early incarnation of the business name (before we'd actually decided on a name). I had expected this to be a bit tedious. In particular, I had started the original repository under my own GitHub account, and then forked it into the company account. Being a private repo, you can't delete the original repository without it deleting any forks (and back in the day ;-) you couldn't even delete repos on GitHub). But, as it turned out, it was pretty easy and didn't take long or involve that much fixing or things that use the code base.



I did ask the GitHub folks for some tips, so these steps factor that info in. Also, before you do any of this, you should of course heed the typical disclaimers, make backups, etc. That said, first, rename the account. You can do this in your Account page on GitHub. Look at the bottom of your account page for this:



Your Account - GitHub
Uploaded with plasq's Skitch!


You don't even need to re-clone your repo for this. Once you've done the rename, you can simply edit your local .git/config file to fix up the account name. Do this anywhere you have cloned the repo - for example on your continuous integration server, deployment scripts, cached copies of code on your staging and deployment servers, Tracker-GitHub post-receive hook service, etc.



Now on to renaming a private forked repo. If you just need to rename a repo, you can do that on the Edit page for a repository and then repeat the above steps:


Administration for chris's tracker_github_hook - GitHub
Uploaded with plasq's Skitch!

But, if you have forked a private repo, it's slightly more involved, but don't fear!



  1. First, make sure you (and anyone else working on the project) have no work in progress, or that you somehow save off that work outside of the repo.

  2. Do a pull from GitHub so you have the most up to date codebase.

  3. On GitHub, delete the original repository (not your forked copy, but from the location you forked it from). This will cascade and delete your forked copy as well. You'll find this right below where you can rename it on the repo's Edit page:
    Administration for chris's tracker_github_hook - GitHub
    Uploaded with plasq's Skitch!

  4. Optionally rename the directory, on your local machine, of the codebase/repo.

  5. Now create a new repository, with your new choice of name, on GitHub.

  6. Then, follow the instructions to import an existing repository. In doing so, on your local machine, go into your codebase, and use that. This will preserve the full Git history and everything from the repository, pushing it up to GitHub just as it was before, but under the new name and rooted at the [new] account.

  7. Fix up all things that use the GitHub account, as mentioned above, like CI servers, deployment scripts, and so on.


That's it, you're done. Pretty straight forward and shouldn't take much time. Thanks again to GitHub for making life so much better in source control land!


3 comments:

Anonymous said...

Thanks for the useful tips.

2shortplanks said...

This would be great - but half the content got thrown away by skitch!

Brian said...

Thanks for the tips, but Skitch is not showing any of the items you posted. Any way you could revise this to elaborate on what was in the Skitch content?