Sometimes we face the problem that we want to synchronise an existing Gitub repository with another repository on Azure DevOps. For example, to deploy from there to Azure. So what is the best way to proceed?


After several attempts, I found the best solution for me.
First, I added the following secrets in the "Secrets" section of the Github Actions:
  1. AZUREPAT (Here you add the Personal Access Token from Azure DevOps. See link).
  2. AZURENAME (Here you add the username from Azure DevOps)
  3. AZUSER_EMAIL (Add the email address you use with your Azure DevOps account here)
  4. AZORG (Here you add the name of the Azure DevOps organisation)
Now I created the following script at the top level of the repository:
git clone ./Moonglade-gh
cd Moonglade-gh
rm -rf .git
cd ..
git clone $GIT_CMD_REPOSITORY ./Moonglade-az
cp -r Moonglade-gh/* Moonglade-az/
cd Moonglade-az
git config --global "$AZUSER_EMAIL"
git config --global "$AZUSERNAME"
git add .
git commit -m "sync from git to azure"
git push
Here I have shown the whole process as an example for my "Moonglade" project.
Both repositories are checked out, then the content of the Github repository is transferred to the checked-out Azure DevOps repository and checked in again.
Finally, the whole thing has to be executed regularly. To do this, create a new Github Actions action:
name: Push directory to another repository
on: push
    runs-on: ubuntu-latest
    environment: AzurePAT
    - uses: actions/checkout@v2
    - name: Run script file
        AZUREPAT: ${{secrets.AZUREPAT}}
        AZUSERNAME: ${{secrets.AZUSERNAME}}
        AZUSER_EMAIL: ${{secrets.AZUSER_EMAIL}}
        AZORG: ${{secrets.AZORG}}
      run: |
         chmod +x ./
      shell: bash
This action would therefore be triggered with every "push". You can also restrict the whole thing to individual branches, which makes perfect sense.
I thank the user harishlalwani for his good advice.