Search code examples
githubgithub-pagesgithub-actions

Github Actions - How can I create file in a new branch


I have a dev branch where I have Gatsby personal website. I also have a main branch accordingly which is used to publish my personal website.

I want to map GitHub pages to my custom domain. For this, I need a new file named CNAME in main with some content.

I found the following GitHub action in order to achieve file creation in the same branch.

https://github.com/marketplace/actions/create-file

I am looking for a similar GitHub action that can create a new file in a new branch.

Here's my current version of GitHub pages:

name: Publish saint1729 Personal Site

on:
  push:
    branches: [ dev ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: enriikke/[email protected]
        with:
          access-token: ${{ secrets.portfolio }}
          deploy-branch: main
          gatsby-args: --prefix-paths

Solution

  • Because of uses: actions/checkout@v2 you have a checkout of your code. You can create a branch by calling git branch the-of-the-branch. And with git push you can push it to the origin repository.