Search code examples
yamlgithub-actions

Set list of branches matching pattern as output variable in GitHub Actions (yml)


I'm trying to create a GitHub action that will output a list of feature/ branches for use in another workflow. My output for this step is always an empty string.

I run this step after running actions/checkout, configuring the git environment, fetching, and traversing to the repo's directory:

echo ::set-output name=branches::$(git branch --list | grep feature/)

However, running this in terminal with the same repo checked out on my machine, I get a list of feature branches.


Solution

  • Using git branch --list will show you just local branches that you checkout locally.

    In GitHub Action checkout action, you are usually checking out just single branch.

    To get all branches despite of the checkout methods, you have to use: git branch -r and grep that one.