Skip to content

Commit 48d6b5a

Browse files
authored
preventing local changes overwritten
all local changes are staged and committed before any git checkout or branch switching,
1 parent a742323 commit 48d6b5a

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

.github/workflows/use-visitor-counter.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ jobs:
5757
git config --global user.name "github-actions[bot]"
5858
git config --global user.email "github-actions[bot]@users.noreply.github.com"
5959
60+
# Pre-commit all changes before any branch switching
61+
- name: Pre-commit local changes
62+
run: |
63+
git add "*.md" metrics.json || true
64+
git commit -m "Save local changes before branch switching" || echo "No changes to commit"
65+
6066
# Commit and push logic for PR events
6167
- name: Commit and push changes (PR)
6268
if: github.event_name == 'pull_request'
@@ -65,10 +71,10 @@ jobs:
6571
run: |
6672
git fetch origin
6773
git checkout ${{ github.head_ref }}
74+
git pull --rebase origin ${{ github.head_ref }} || echo "No rebase needed"
6875
git add "*.md" metrics.json
6976
git commit -m "Update visitor count" || echo "No changes to commit"
7077
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
71-
git pull --rebase origin ${{ github.head_ref }} || echo "No rebase needed"
7278
git push origin HEAD:${{ github.head_ref }}
7379
7480
# Commit and push logic for non-PR events (schedule, workflow_dispatch)
@@ -79,10 +85,10 @@ jobs:
7985
run: |
8086
git fetch origin
8187
git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} origin/${{ github.ref_name }}
88+
git pull --rebase origin ${{ github.ref_name }} || echo "No rebase needed"
8289
git add "*.md" metrics.json
8390
git commit -m "Update visitor count" || echo "No changes to commit"
8491
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
85-
git pull --rebase origin ${{ github.ref_name }} || echo "No rebase needed"
8692
git push origin HEAD:${{ github.ref_name }}
8793
8894
- name: Create Pull Request (non-PR)

0 commit comments

Comments
 (0)