I have two branches:
- main
(Contains nothing but just a README.md
)
- my-branch
(Contains some files and folders with subfolders)
- gh-pages
(This will be deployed using GitHub Pages settings)
I want to copy all content of my-branch
into a folder called myFolder
inside gh-pages
whenever there's a push to my-branch
. How can I implement that in YAML?
PS: I was initially trying to copy just the files that has changed, maybe using rsync, but found that it was too difficult, so I guess I'll copy the entire thing every time there's a push, but if you have any better way, please help.
Edit: Here's what I've gotten so far.
name: Copy files to another branch
on:
push:
branches:
- better-page
workflow_dispatch:
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
copy:
runs-on: ubuntu-latest
steps:
- name: Checkout better-page
uses: actions/checkout@v2
with:
ref: better-page
- name: Copy files
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "action@github.com"
rsync -r --exclude=.git --exclude=.github --exclude=about-me --exclude=node_modules --exclude=simplified . simplified/
git add .
git diff-index --quiet HEAD || git commit -am "create simplified directory" # commit to the repository (ignore if no modification)
git push origin better-page # push to remote branch
git checkout gh-pages
git fetch origin gh-pages
git pull origin gh-pages
git push origin gh-pages
git checkout better-page
git fetch origin better-page
git pull origin better-page
git push origin better-page
git checkout gh-pages
git checkout remotes/origin/better-page -- simplified
git add -A
git diff-index --quiet HEAD || git commit -am "deploy files"
git push origin gh-pages
git checkout better-page
rm -rf simplified
git add -A
git diff-index --quiet HEAD || git commit -am "remove simplified directory"
git push origin better-page
But it gave me this error
Everything up-to-date
error: pathspec 'gh-pages' did not match any file(s) known to git
Error: Process completed with exit code 1.
I don't know what's going on or what to do.