I am trying to create a workflow to backup files in my local repository: once per day, add everything that changed, create a commit and push it to main.
Let’s say the repository contains a changed file Daily.md
. Running git status
in my local repository tells me “hey, something changed!”:
# git status
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: Daily.md
no changes added to commit (use "git add" and/or "git commit -a")
What I would normally do is something like git add .
followed by git commit -m "awesome change"
and git push
. This is exactly what I expect the workflow to do.
This is my workflow so far:
name: Daily Backup
on:
workflow_dispatch:
schedule:
- cron: '0 2 * * *'
jobs:
backup:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
ref: 'main'
- name: checkout main
run: git checkout main
- name: show files
run: ls -la
- name: git status
run: git status
- name: Add & Commit
run: |
git config user.email [email protected]
git config user.name "Github Actions"
git add -A
git commit -m "test"
- name: git push
run: git push
However, the changed Daily.md
file is not recognized as “changed”. Looking into the actions’ log shows that git status
in my workflow does not recognize anything has changed (even though a local git status
shows Daily.md
as unstaged change like shown above).
What am I doing wrong here? I do not understand why a changed file in my local repo is not recognized as changed (and therefore added, committed and pushed) by my workflow.
3