Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to set init.defaultBranch during FETCHSOURCE

How can I set git config --global init.defaultBranch main during the FETCHSOURCE step in google cloud build?

My mission is silencing this redundant message:

hint: Using 'master' as the name for the initial branch. This
default branch name hint: is subject to change. To configure the
initial branch name to use in all hint: of your new repositories,
which will suppress this warning, call: hint: hint:     git config
--global init.defaultBranch <name>

I've tried this in step 0 of cloudbuild.yaml but it runs after FETCHSOURCE

steps:
- name: 'gcr.io/cloud-builders/git'   
args: [ 'config', '--global', 'init.defaultBranch', 'master']
0 4 80
4 REPLIES 4

Hi @tonymet,

Welcome to Google Cloud Community.

You might want to check this repository from github or this document for your reference for your cloud build. 

For further assistance, please reach out to the Google Cloud Support team.

Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.

cloudbuild.yaml steps execute AFTER fetchsource. What i need help with is how to configure FETCHSOURCE

Hello @tonymet ??? I totally get what you're trying to do. That annoying hint: Using 'master' as the initial branch name. message — it shows up when you're performing FETCHSOURCE, and yep, git config --global init.defaultBranch main in your subsequent build steps doesn't cut it. Been there ????Why it's happeningFETCHSOURCE is run prior to your own actions of construction beginning. So even when you have set in step 0, it's too late already — Git has already run with defaults.What you can do instead???? Choice 1: Custom builder imageYou can create your own Docker image with that configuration already set. Something like:FROM gcr.io/cloud-builders/gitRUN git config --global init.defaultBranch mainThen, in your cloudbuild.yaml, substitute the default git one with this custom image.???? Option 2: Just ignore it (if it is not breaking thingsActually, it's a warning. Does not impact your build unless you're authoring something that depends upon the default branch name.

???? Option 3: Use repo which already has main set

If you're adding repos manually, just run this once locally:

git config --global init.defaultBranch main

Then your new repos will default to main, and warnings will end.

thanks that sounds like a step in the right direction.  where in cloudbuild.yaml to I set the build image for FETCHSOURCE? i only see build images for - steps