Skip to content

Instantly share code, notes, and snippets.

@drewwyatt
Created October 26, 2023 22:17
Show Gist options
  • Save drewwyatt/cc4e688738575e7cd230ca2e45c5f1e6 to your computer and use it in GitHub Desktop.
Save drewwyatt/cc4e688738575e7cd230ca2e45c5f1e6 to your computer and use it in GitHub Desktop.
Create a new branch only if one doesn't already exist
name: Create or Update Branch
on:
workflow_dispatch:
inputs:
branch:
required: true
jobs:
checkout-branch:
runs-on: ubuntu-latest
steps:
- name: Initial Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch depth 0 means "pull the whole thing"
token: ${{ secrets.GH_PAT }}
- name: Checkout Branch and Perform Initial Config Setup
env:
BRANCH: ${{ inputs.branch }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "Robot"
git config pull.ff only
git fetch # just in case?
# try to checkout an existing branch first
# (and use this as a starting point when creating the new branch below)
# if we don't find a branch here, this will just create our new branch from the trunk
if git checkout "origin/$BRANCH" ; then
git pull origin "$BRANCH"
fi
git checkout -B "$BRANCH" # create a "new" branch
- name: Modify some files
run: echo "test" >> ./test
- name: Push the changes
env:
BRANCH: ${{ inputs.branch }}
run: |
git add .
git commit -m 'test'
git push origin "$BRANCH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment