Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --no-git flag #13502

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docusaurus/docs/getting-started.md
Expand Up @@ -88,6 +88,10 @@ npx create-react-app my-app --template typescript

If you already have a project and would like to add TypeScript, see our [Adding TypeScript](adding-typescript.md) documentation.

### Disabling git repo initilization

By default, a git repo is created in the `my-app` directory. You can disable the creation of this git repo using the `--no-git` flag.

### Selecting a package manager

When you create a new app, the CLI will use [npm](https://docs.npmjs.com) or [Yarn](https://yarnpkg.com/) to install dependencies, depending on which tool you use to run `create-react-app`. For example:
Expand Down
14 changes: 9 additions & 5 deletions packages/create-react-app/createReactApp.js
Expand Up @@ -74,6 +74,7 @@ function init() {
'specify a template for the created project'
)
.option('--use-pnp')
.option('--no-git')
.allowUnknownOption()
.on('--help', () => {
console.log(
Expand Down Expand Up @@ -226,13 +227,14 @@ function init() {
program.scriptsVersion,
program.template,
useYarn,
program.usePnp
program.usePnp,
program.noGit
);
}
});
}

function createApp(name, verbose, version, template, useYarn, usePnp) {
function createApp(name, verbose, version, template, useYarn, usePnp, noGit) {
const unsupportedNodeVersion = !semver.satisfies(
// Coerce strings with metadata (i.e. `15.0.0-nightly`).
semver.coerce(process.version),
Expand Down Expand Up @@ -326,7 +328,8 @@ function createApp(name, verbose, version, template, useYarn, usePnp) {
originalDirectory,
template,
useYarn,
usePnp
usePnp,
noGit
);
}

Expand Down Expand Up @@ -401,7 +404,8 @@ function run(
originalDirectory,
template,
useYarn,
usePnp
usePnp,
noGit
) {
Promise.all([
getInstallPackage(version, originalDirectory),
Expand Down Expand Up @@ -486,7 +490,7 @@ function run(
cwd: process.cwd(),
args: nodeArgs,
},
[root, appName, verbose, originalDirectory, templateName],
[root, appName, verbose, originalDirectory, templateName, noGit],
`
const init = require('${packageName}/scripts/init.js');
init.apply(null, JSON.parse(process.argv[1]));
Expand Down
21 changes: 14 additions & 7 deletions packages/react-scripts/scripts/init.js
Expand Up @@ -86,7 +86,8 @@ module.exports = function (
appName,
verbose,
originalDirectory,
templateName
templateName,
noGit
) {
const appPackage = require(path.join(appPath, 'package.json'));
const useYarn = fs.existsSync(path.join(appPath, 'yarn.lock'));
Expand Down Expand Up @@ -273,12 +274,6 @@ module.exports = function (
// Initialize git repo
let initializedGit = false;

if (tryGitInit()) {
initializedGit = true;
console.log();
console.log('Initialized a git repository.');
}

let command;
let remove;
let args;
Expand All @@ -295,9 +290,21 @@ module.exports = function (
'--no-audit', // https://github.com/facebook/create-react-app/issues/11174
'--save',
verbose && '--verbose',
noGit,
].filter(e => e);
}

if (noGit) {
console.log();
console.log('Skipping initialize git repository');
} else {
if (tryGitInit()) {
initializedGit = true;
console.log();
console.log('Initialized a git repository.');
}
}

// Install additional template dependencies, if present.
const dependenciesToInstall = Object.entries({
...templatePackage.dependencies,
Expand Down