Migrate git repositories
Usage
Azure Repo to Azure Repo (Azure DevOps)
- Make sure Azure CLI is installed and Azure DevOps extension has been added (ref. Get started with Azure DevOps CLI)
az --version
az extension add --name azure-devops
- Configure git to avoid issues
git config --global pager.tag false
- Connect to Azure (ref. Sign in with a personal access token)
az login
# or
export AZURE_DEVOPS_EXT_PAT=xxxxxxxxxx
- Run the migration script (ref. az repos)
scripts/migrate_azure_repos.sh <oldorg> <oldproject> <oldrepo> <neworg> <newproject> <newrepo> <repoid> <tempdirpath>
- Optionnally, migrate all repositories of a project
while read repository
do
name=$(echo "$repository" | jq -r .name)
id=$(echo "$repository" | jq -r .id)
echo "Repository ${id}, ${name}"
scripts/migrate_azure_repos.sh <oldorg> <oldproject> $name <neworg> <newproject> <someprefix>$name $id <tempdirpath>
done < <(echo `az repos list --organization https://dev.azure.com/<oldorg> --project <oldproject>` | jq -c '.[]')
Behind the scenes
General workflow
- Clone origin repository
- Checkout all branches
- Create destination repository
- Set destination remote
- Push all branches with tags to destination
- Check destination content
- Delete origin repository