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

[create-next-app]: respecting the user's init.defaultBranch git con… #49960

Merged
merged 5 commits into from May 20, 2023
Merged
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
12 changes: 11 additions & 1 deletion packages/create-next-app/helpers/git.ts
Expand Up @@ -19,6 +19,14 @@ function isInMercurialRepository(): boolean {
return false
}

function isDefaultBranchSet(): boolean {
try {
execSync('git config init.defaultBranch', { stdio: 'ignore' })
return true
} catch (_) {}
return false
}

export function tryGitInit(root: string): boolean {
let didInit = false
try {
Expand All @@ -30,7 +38,9 @@ export function tryGitInit(root: string): boolean {
execSync('git init', { stdio: 'ignore' })
didInit = true

execSync('git checkout -b main', { stdio: 'ignore' })
if (!isDefaultBranchSet()) {
execSync('git checkout -b main', { stdio: 'ignore' })
}

execSync('git add -A', { stdio: 'ignore' })
execSync('git commit -m "Initial commit from Create Next App"', {
Expand Down