Problem

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?
 

Solution

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 commit.sh script at the top level of the repository:
 
AZUREPAT=$AZUREPAT
AZUSERNAME=$AZUSERNAME
AZUSER_EMAIL=$AZUSER_EMAIL
AZORG=$AZORG
git clone https://github.com/saigkill/Moonglade ./Moonglade-gh
cd Moonglade-gh
rm -rf .git
 
cd ..
 
GIT_CMD_REPOSITORY="https://$AZUSERNAME:$AZUREPAT@dev.azure.com/$AZORG/Moonglade/_git/Moonglade"
git clone $GIT_CMD_REPOSITORY ./Moonglade-az
 
cp -r Moonglade-gh/* Moonglade-az/
 
cd Moonglade-az
 
git config --global user.email "$AZUSER_EMAIL"
git config --global user.name "$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
jobs:
  check-bats-version:
    runs-on: ubuntu-latest
    environment: AzurePAT
    steps:
    - uses: actions/checkout@v2
    - name: Run script file
      env:
        AZUREPAT: ${{secrets.AZUREPAT}}
        AZUSERNAME: ${{secrets.AZUSERNAME}}
        AZUSER_EMAIL: ${{secrets.AZUSER_EMAIL}}
        AZORG: ${{secrets.AZORG}}
      run: |
         chmod +x ./commit.sh
         ./commit.sh
      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.