Ashraf Ullah
Ashraf Ullah

Reputation: 21

Is there a way to import multiple repos at once from github into azure devops?

I have an organization in github with 100+ repos that I would like to move into azure devops. Right now it seems like I have to manually import each project repo into azure devops. Is there a way for me to pull multiple at once? Thank you.

I have not been able to find anything similar to this online.

Upvotes: 1

Views: 872

Answers (2)

KATHY WEN LEE
KATHY WEN LEE

Reputation: 11

$gitHubOrg = "your-github-org"
$azureDevOpsOrg = "your-azdo-org"
$azureDevOpsProject = "your-azdo-project"

gh auth login

$repos = convertfrom-json (& gh repo list $gitHubOrg --json name) 

echo "Migrating these repos: "
echo $repos

az devops login --organization https://dev.azure.com/$azureDevOpsOrg

foreach ($repo in $repos)
{
  $repoName = $repo.name
  echo "Migrating repo " $repoName
  & az repos create --name $repoName --organization https://dev.azure.com/$azureDevOpsOrg --project $azureDevOpsProject 
  & git clone --mirror https://github.com/$gitHubOrg/$repoName.git $repoName
  pushd $repoName
  & git lfs fetch --all
  & git remote add azure-devops https://dev.azure.com/$azureDevOpsOrg/$azureDevOpsProject/_git/$repoName
  & git push --mirror azure-devops
  & git lfs push azure-devops --all
  echo "Migrated repo " $repoName
  popd
}

Upvotes: 1

jessehouwing
jessehouwing

Reputation: 114751

This is relatively easy to script. Use the GitHub cli gh repo list $orgname to list all repos in the source. Use az repos create to create a new repo in the target org.

& gh auth login

$gitHubOrg = "mycompany"
$repos = convertfrom-json -raw (& gh repo list $gitHubOrg --json name) 

& az devops login --organization https://dev.azure.com/$azureDevOpsOrg

Then use the standard CLI to clone each repo and push it to the remote

$azureDevOpsOrg = "myOrg"
$azureDevOpsProject = "myProject"

foreach ($repo in repos)
{
  & az repos create --name $repo --organization https://dev.azure.com/$azureDevOpsOrg --project $azureDevOpsProject 
  & git clone --mirror https://github.com/org/$repo.git $repo
  pushd $repo
  & git lfs fetch --all
  & git remote add https://dev.azure.com/$azureDevOpsOrg/$azureDevOpsProject/_git/$repo
  & git remote add azure-devops
  & git push --mirror azure-devops
  & git lfs push azure-devops --all
  popd
}

To push each repo into Azure DevOps.

In case you're connecting to Azure DevOps Server, you need to replace: https://dev.azure.com/$azureDevOpsOrg with https://servername/collectionname, e.g. https://tfs.mycompany.com/DefaultCollection or (if it's an older or upgraded installation) https://tfs.mycompany.com/tfs/DefaultCollection

Above example in PowerShell assuming you have the following tools installed:

Upvotes: 1

Related Questions