Bootstrap FreeKB - GitHub Actions - Copy files between repos
GitHub Actions - Copy files between repos

Updated:   |  GitHub Actions articles

Let's say you have a file in repo "a" that you want to copy to repo "b". Here is an example GitHub Action that could be used.

name: Copy File
run-name: ${{ github.workflow }} run by ${{ github.actor }}
on:
  push:
    branches:
      - main
jobs:
  copy-file:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the my_org/repo_a repo
        uses: actions/checkout@v4
        with:
          repository: 'my_org/repo_a'
          path: 'repo_a'
          
      - name: Checkout the my_org/repo_b repo
        uses: actions/checkout@v4
        with:
          repository: 'my_org/repo_b'
          path: 'repo_b'

      - name: copy foo.txt from repo_a to repo_b
        run: cp repo_a/path/to/foo.txt repo_b/path/to/foo.txt

      - name: git commands
        run: |
          cd repo_b; 
          git config user.name "John Doe";
          git config user.email "john.doe@example.com";
          git add path/to/foo.txt;
          git commit -m "it's a wonderful day in the neighborhood" path/to/foo.txt;
          git push origin HEAD;

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 72ca6c in the box below so that we can be sure you are a human.