Created by: giovannibenussi
What Adds This PR?
This change allows to create new projects with a custom branch name:
npx create-react-app my-app --branch-name main
Why?
There is a lot of interest in the community to end with racist or patriarcal background. Even GitHub changed its default branch to main for new repositories. We should allow people to provide a custom branch name to initialize their CRA projects as requested in #9748 (closed).
Solution Details
The proposed solution tries to run git init --initial-branch=custom-branch
first if a custom branch name is provided. If there's an error running this command, it runs git init
as a fallback. Why this? Because git throws an error if you run git init
with --initial-branch
on versions prior to 2.28.0. Try to get the output from git --version
failed because execSync('git --version', { stdio: 'ignore' });
returns null.
Extras
I tried to configure init.defaultBranch in my computer but my git version is 2.26.2 and that feature was added on 2.28.0. I don't want to upgrade my git version yet since we may need to test this change on old git versions.
Questions
I'd like to know how to test this changes as similar as possible as running npx create-react-app ...
.
I was able to partially test my changes by running yarn create-react-app my-app --branch-name main
after cloning this repository. However, since a git repository is already initialized, I wasn't able to check that this changes worked. I'm only sure that the custom branch name is passed down to the expected functions (mostly by running console.logs), so test that this changes work as expected is necessary.
An automated test would be really nice, but if not possible, a manual way to test is great too.