How to get git branch on eas localy build?

My preset env:

  1. managed workflow
  2. eas-cli/5.4.0 darwin-arm64 node-v16.20.0

I want to use my [git branch] in app.config.ts when I build my app locally, so I use const BRANCH_NAME = execSync('git branch --show-current').toString(); to get [git branch].
But when I execute eas build --profile [pfoile] --local it will show error: “fatal: not a git repository (or any of the parent directories): .git”.

My question: How can I get branch name in locally build?

Hi @moego_sam

I think what’s going on is the following:

When you run eas build --local, eas copies your files to a temporary directory and then runs the build there. I suppose that when it tries to get the branch name it is running in the temporary directory instead of in your Git repository.

Maybe what you could do is add a script to package.json to get the branch name and then call eas build --local

Maybe something like this (untested):

  "scripts": {
    "build": "BRANCH_NAME=$(git branch --show-current) eas build --local --profile"

and you could call it like this:

$ npm run build -- profilename