Mo B.
Mo B.

Reputation: 5805

How to mirror a specific branch between two Azure DevOps/VSTS repositories

I have a Azure DevOps/VSTS project with two Git repositories, repoMain and repoMirror. The repository repoMain has a Master branch and a separate branch newBranch. The repository repoMirror is still empty.

How can I set up a build pipeline (with a Command Line task? Powershell task?) such that whenever something is checked in into newBranch, the changes are pushed into the other repository repoMirror? In other words, repoMirror should always (and only) contain the current contents of newBranch.

Upvotes: 1

Views: 968

Answers (1)

Shamith Wimukthi
Shamith Wimukthi

Reputation: 525

Recently I also tried this for one of my projects. Let me give you all the steps that I followed.

  1. Firstly create a newBranch branch in the repoMirror

  2. Now create a CI build pipeline using a windows agent

  3. Add a PowerShell script task with the following commands

git clone https://[email protected]/org/project/_git/repoMain

cd repoMain

git checkout newBranch

git remote add Reponame https://[email protected]/org/project/_git/repoMirror

git push Reponame newBranch -f

enter image description here

  1. Finally create a trigger for repoMain --->newBranch So when ever there is any code update in repoMain --->newBranch the pipe will be executed

    enter image description here

Upvotes: 1

Related Questions