Peter Mekhaeil

Using GitHub Actions to push changes

We can use GitHub Actions to push a new commit each time there is a new change detected.

I've recently had to do this to automate updating with a listing of the repository files each time a new push has been detected. The GitHub workflow is found here.

Here are the learnings that may come useful to others:

Using bash to clear file content

cat /dev/null >

/dev/null is a pseudo file in Linux that has no output so we can override a file with this empty content.

Using bash to echo a string with new line

echo -e '# Today I Learned\n' >

-e is required to escape backslashes. This allows us to print new line (\n) when outputting to a file.

Using bash to read the first line of a file

head -n 1 $filename

Using bash to remove characters from a string

echo '# Title' | sed 's/# //'

sed is short for Stream EDitor and one of its common uses is pattern replacement. The above will remove # from the string (by replacing it with an empty string).

Using bash to append string to file

echo 'My string' >>

The >> operator is used to append to a file (or create the file if it does not exist).

Using GitHub Actions to push changes to a repository

actions/checkout is an offical GitHub Action that can checkout a repository. We can also use this to push changes back.

on: push
    runs-on: ubuntu-latest
      - uses: actions/checkout@v2
      - run: |
          # Clear
          cat /dev/null >

          # Add Title
          echo -e '# Today I Learned\n' >

          # Loop through all TILs and add to
          for filename in "$dir"/*
            title=$(head -n 1 $filename | sed 's/# //')
            echo "- [$title]($filename)" >>

          # Push changes
          git config github-actions
          git config
          git add
          git commit -m "Update"
          git push