Github Actions on push not master

I am trying to figure out what the syntax would be for running a workflow, on push, on any branch but master. I read through some other posts here that looks like folks are having issues with the tag filtering, so maybe this is related?

If I use code like:

on:
  push:
    branches:
      - '*'
      - !master

This will throw the error:

### ERRORED 14:48:42Z

- Your workflow file was invalid: .github/workflows/main.yml: Unexpected tag '!master'

Does anyone know the syntax I am looking for?

Thank you in advance!

1 Like

To answer my own question, the syntax appears to be:

on:
  push:
    branches:
      - /refs/heads/*
      - !master

Edit: This is not the correct implementation, and only appeared to work since I had different workflow files in the master and test branches.

I’ve found that putting quotes around !master works, but I’m not sure if it’s technically correct:

on:
  push:
    branches:
      - '*'
      - '!master'
11 Likes

@arpanlaha @csumpter 

We’ve been using this at the top of our default.yml workflow with success.

on:
  push:
    branches:
    - !master

Hope that helps!

Edit:
This apparently is no longer working – or just appeared to work somehow.

The good news is that @arpanlaha 's solution works fine for me.

@arpanlaha @intolerance 

@arpanlaha- your solution works perfectly. Thank you so much for helping out! I will flag your code as the solution.

Leading bangs are reserved for custom tags in YAML. So you need to always use explicit strings.

1 Like

You need quotes when the branch/tag starts with a ! or *. 

Thank you @jeremyepling. I see that docs have been updated on https://help.github.com/en/articles/workflow-syntax-for-github-actions to reflect the same.

on:
  push:
    branches:
      - '*'
      - '!master'

Does not seem to work for me. :frowning:

name: CI
on:
push:
branches:
- '*'
- '!master'

 Works perfectly! Thanks a lot.

1 Like

For anyone where the solution is not working. This happened to me:

I was pushing to a branch called ‘release/1.0.1’ and the wildcard ‘*’ does not seem to work for this naming. You also need to set ‘*/*’ to make this work.

As described on https://golang.org/pkg/path/#Match ‘*’ : 

matches any sequence of non-/ characters 
3 Likes

Similarly to the problem that @verbruggenalex highlighted, the double ** will work as well:

on:
  push:
    branches:
      - '**'
      - '!master' 
    paths: 
    - 'somepath/**'

The documentation here states:

  • * : Matches zero or more characters, but does not match the / character. For example, Octo* matches Octocat .
  • ** : Matches zero or more of any character.
1 Like

Thanks for this, hopefully this can be marked as the solution instead of what I had previously.

Using branches-ignore from the official docs:

on:
  push:
    branches-ignore:
      - master
1 Like