# Push Changes From GitHub to GitLab ## Metadata **Status**:: #x **Zettel**:: #zettel/permanent **Created**:: [[2023-05-20]] **Tags**:: #automation #github-actions **Topic**:: [[♯ Automation]] ## Synopsis To sync two projects on GitLab and GitHub, follow these steps: 1. [[Generate SSH Key Pair]] ```shell ssh-keygen -t ed25519 -C "gitlab sync" -f id_ed2551 ``` 2. Upload the public key to the GitLab project as a deploy key with write permission. 3. Set the private key as the secret `DEPLOY_KEY` in the GitHub project. 4. [[Obtain Known Hosts Entry for SSH|Obtain the known hosts entry for gitlab.com]] and set it as the secret `KNOWN_HOSTS`. 5. Create a `gitlab-sync.yaml` workflow as below. > [!file] `gitlab-sync.yaml` > ```yaml > name: Gitlab Sync > > on: > push: > branches: > - main > > concurrency: > group: ${{ github.ref }} > cancel-in-progress: true > > jobs: > sync: > name: Gitlab Sync > runs-on: ubuntu-latest > steps: > - uses: actions/checkout@v3 > with: > fetch-depth: 0 > - name: Install SSH key > uses: shimataro/ssh-key-action@v2 > with: > key: ${{ secrets.DEPLOY_KEY }} > known_hosts: ${{ secrets.KNOWN_HOSTS }} > - name: Push to Gitlab > run: | > git remote add gitlab [email protected]:${{ github.repository }}.git > git push --force gitlab HEAD > ``` ## Alternatives ### Shallow Backup Do not backup history. 1. Remove `fetch-depth` option in the checkout step. 2. Add the following line before `git push` ``` git reset $(git commit-tree "HEAD^{tree}" -m "A new start")` ```