How to move a GIT Repo from GitHub to Azure

Azure, Amazon, Gitlab, Bitbucket, any provider that hosts GIT repositories

Moving Repo from Github to Azure

This is a simple way to move a codebase to Azure, Amazon, Gitlab, Bitbucket, any provider that hosts GIT repositories. I'm moving from GitHub to Azure but the steps are the same.

Create a empty repo on your target to host your code.

First I pulled a clean copy from GitHub to my laptop into a new directory I named azure

This is how I did it, you will need to login to your target repo host and add your ssh key. This is different on every host. Below is an Apple way to copy your key to the clipboard.

cat ~/.ssh/id_rsa.pub | pbcopy

Next after you can commit to the repo, you need to pull a clean copy of the repo, add the remote for the Azure container, then fetch all the tags, and checkout all the branches, then push to the Azure remote. Here are the exact commands I used to move it, I’ve used these commands a lot over the years to move client code from their old web developer’s GitHub to my Bitbucket or GitHub account.

cd ~
git clone #use ssh github clone link* azure
## Add remote named azure
git remote set-url azure *replace with target repo ssh link*
## List remotes 
git remote -v
## Fetch all tags and commit history
git fetch origin --all --tags -v
## Fetch all branches
for remote in git branch -r | grep -v master ; do git checkout --track $remote ; done
## now push everything to the remote azure you set earlier
git push azure --all

And that is all there is to it honestly. It took me maybe 10 minutes once I found my old notes on moving origins.

After the code is moved, you can rename origin to github and rename azure too origin so when you push code it will automagically go into the Azure repo.

Shawn Crigger

Did you find this article valuable?

Support Shawn Crigger by becoming a sponsor. Any amount is appreciated!