Hi, I'm Nicholas 👋

I'm a Senior Platform Engineer

Buy Me A Coffee

Using Git to push to Multiple Repos

Date published:

This post will show you how to add a secondary repo to your local Git. I have been struggling to find out how to push to a secondary repo. I wanted to use Azure DevOps Repo and Github and make one internal and the other external to the public. The ideal set-up would be making Azure DevOps Repo private and the Github Public so other people can see it.

Creating a Project via Azure DevOps

1). Login to your Azure DevOps via the portal and sign in to your organisation https://wwww.dev.azure.com/organisationname. Create a project using the new project tab, give it a name and description, and make it private. In my example, I have created a test project called Github Test.

2). Go to the project Repos and you should see that it is an empty repository. Click on it on the clone to VS code to clone it locally to visual studio code on your machine.

3). When you have the project open in Visual studio code, you can confirm that it is from Azure DevOps Repo by running the Git remote -v, which you should see a list of remote origins. This origin is the central location the project created and where your local Git fletches for changes. The only git commit is locally, and it is not shared until you commit it to the remote branch.

Adding Secondary Repository

If you need to push to a secondary repo, you will need to add another origin to it. I will be showing you how to push to Github. Below is the empty repo in GitHub used as a secondary origin to your project to be able to push code to it.

You can set up the secondary origin by taking your origin URL and using the git remote add command followed by a name. I have decided to call mine secondary, but you can also call it any name you like.

git remote add secondary https://github.com/nicholaschangIT/Github-Test.git

Now we will try to make a commit to the Azure DevOps Repo first before committing to Github. The main is the branch name of your repo. After the commit, you would need to say git push secondary or the remote’s name previously. I have used the git push origin command to push the commit.

Azure DevOps Repo

Github Repo

Results

Thank you for reading and I hope you like it :)

References: