1

We work in projects connected to azure devOps as Git Repos. There are 2 different repositories, repo-A and repo-B.

enter image description here

What i need is, whenever i change a "fileS" in any repository (by commit and push), it should update the other "fileS" in the other repository to keep both files synchronized.

Is there any solution using Azure pipeline to automatic push in the second repository or any other solution? Thank you

SymbolKina
  • 21
  • 3
  • What happens when there are conflicting changes made in two separate commits in the two separate repositories at the same time? (I can make ten commits per second per repository and push them all at once!) – torek Mar 24 '22 at 15:40
  • @torek thanks for your reply, resolve merge can be used?? – SymbolKina Mar 24 '22 at 15:47
  • Merge requires a merge base; where will you get the merge base? In any case there are multiple issues here: one is resolving any conflicts, one is getting the files in question out of specific commits (these two may be Git questions), and one is using azure to make new commits (this is an Azure question). You should probably divide this up a bit. – torek Mar 24 '22 at 15:49
  • you are right. and what about a simple copy after push in all remote repositories? I tried a lot of way using azure pipeline, any of its worked. i tried to use Git Hooks and it seems work but you give me a clarification about one of must important consideration to manage ( conflict case). thank you – SymbolKina Mar 24 '22 at 15:55
  • I don't know the Azure-pipelines stuff so I can't really help there. It's just something to think about: whenever you automate something, try to imagine all the ways it could go wrong. :-) – torek Mar 24 '22 at 15:56
  • okay, we want to get the same feature as visual SourceSafe shared file that is why we are searching other alternatives. – SymbolKina Mar 24 '22 at 16:04

1 Answers1

0

Is there any solution using Azure pipeline to automatic push in the second repository or any other solution?

There is no directly settings you could do that, but you could create a pipeline to invoke the git command to sync the single file between 2 different repositories.

Create a pipeline for the Repo A with trigger settings:

enter image description here

Then add inline powershell task:

cd $(Agent.BuildDirectory)
git clone https://PAT-HERE@dev.azure.com/{organzition}/{project}/_git/{repo-name}
cd {repo-name}
git checkout branch-name # if the synced file not in master
# Assuming the synced file name is "test.txt" and he exists in the folder "common"
Copy-Item $(Build.SourcesDirectory)\_fileS $(Agnet.BuildDirectory)\{repo-name} -Force
git config --globa user.email "xxxx.com" 
git config --global user.name "xxxxx"
git add common/_fileS
git commit -m "Sync _fileS"
git push
Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Thank you for you r reply. Your solution is very helpful but if I have 50 common files I need to copy them all in the second repository and execute git add 50 times for each file, does exist any way to add a group of files in stead of to do it singularly? Thank you – SymbolKina Mar 25 '22 at 08:21
  • @SymbolKina, Yes, check the git command, https://stackoverflow.com/questions/19576116/how-to-add-multiple-files-to-git-at-the-same-time – Leo Liu Mar 28 '22 at 06:00
  • Thank you i will check and test it then let you know. – SymbolKina Mar 28 '22 at 07:14