How to move a code repository from Devops to Github

How to move a code repository from Devops to Github

Table of Contents

A long time ago in a galaxy far, far away…

This post is over 24 months old, that is an lifetime in tech! Please be mindful of that when reading this post, young Padawan, as it could be outdated. I try to keep things up to date as much as possible. If you think something needs updating, please let me know in the comments.

Introduction

I wanted to migrate a repository from Azure DevOps repos to Github whilst preserving as much of my content as possible. It turns out it was really straightforward using Github importer. This feature is available for source code in Subversion, Mercurial, Team Foundation Version Control, and Git. I am looking at migrating a git repository hosted in an Azure DevOps project.

Commit and push your code

Firstly, you will need to be mindful that git is a decentralised version control system. Changes to your repository occur locally. As such the remote repository will only be aware of changes that have been committed and pushed back. Therefore, if you want to ensure that all changes are migrated, you need to commit them and push them back to the repository before starting this migration. This goes for every person who is contributing to your repository.

Prepare DevOps repository

Firstly, you’ll need to get some information from DevOps and set up credentials for Github to authenticate. Open DevOps and navigate to the repos section of the project where the source repository is located. You’ll have to have the files section option to see the clone button.

open Azure DevOps project, then repos section and press the clone button

You will then see a sidebar appear with some options. Firstly press the “generate git credentials” button. We’ll use these credentials to allow Github to authenticate with DevOps to import the repository.

from the sidebar, press the generate git credentials button

Azure DevOps will generate a username and password. You will need the URL, the username, and the password during the import process in Github so make a note of them.

devops has generated a username and password along with a URL

Import repository

Open the main Github page, locate the new button and click it to create a new repository.

we can create a new repository by pressing the new button from the main page

Located just under the “create a new repository” header, you’ll find a link to import a repository. Click this to start the import process.

just under the create a new repository header is a link to import a repository

First, you’ll be asked for the repository’s URL and to give the repository a name. This is not the current name of the repository, but what you wish to call it in Github. If you want to give your repository an entirely different name, you can.

Enter the repository URL which was displayed in DevOps and name your new repository

You will then be asked for credentials to access the DevOps repository. These are the credentials that Azure DevOps generated earlier. These will be stored temporarily during the import process.

Github needs to temporarily store your credentials in order to import the repository

And that is it! After a short period, Github will report that the import is complete. You will then find your repository available to access from Github.

Github has successfully imported the repository

This will preserve all open branches and commit history. Note, I haven’t tested this with open pull requests tested thi

Next steps

  • This is a non-destructive action, so you may want to archive the Azure DevOps repository to ensure that work doesn’t continue in two places.
  • Your local version of the repository will currently be pointing at the Azure DevOps repository. If you wish to work on the Github version you will need to fix this. You have a few options here;
    • change the remote URL of your local repository
    • remove the current folder and re-clone
    • clone the Github repository to a new location
  • You may also wish to update the referenced repository so that the Github version is available in Azure DevOps.

I will look at these things in future posts.

Summary

We have successfully migrated a git repository from Azure DevOps to Github and preserved the commit history and all branches. Not all functionality is available to each source code system, so refer to the Github docs for more information.

Additional Reading

#mtfbwy



Recent Posts