Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !10202

Allow custom branch names

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Administrator requested to merge github/fork/giovannibenussi/master into main Dec 05, 2020
  • Overview 6
  • Commits 1
  • Pipelines 0
  • Changes 2

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.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/giovannibenussi/master