Skip to content

Commit d487f85

Browse files
committed
Add the ability to change the branch name from "main"
1 parent 4816a03 commit d487f85

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/NewCommand.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ protected function configure()
2727
->addArgument('name', InputArgument::REQUIRED)
2828
->addOption('dev', null, InputOption::VALUE_NONE, 'Installs the latest "development" release')
2929
->addOption('git', null, InputOption::VALUE_NONE, 'Initialize a Git repository')
30+
->addOption('branch', null, InputOption::VALUE_REQUIRED, 'Set your branch name, defaults to "main"')
3031
->addOption('github', null, InputOption::VALUE_OPTIONAL, 'Create a new repository on GitHub', false)
3132
->addOption('organization', null, InputOption::VALUE_REQUIRED, 'The GitHub organization to create the new repository for')
3233
->addOption('jet', null, InputOption::VALUE_NONE, 'Installs the Laravel Jetstream scaffolding')
@@ -207,8 +208,10 @@ protected function createRepository(string $directory, InputInterface $input, Ou
207208
{
208209
chdir($directory);
209210

211+
$branch = $input->getOption('branch') ?: 'main';
212+
210213
$commands = [
211-
'git init -q -b main .',
214+
"git init -q -b $branch .",
212215
'git add .',
213216
'git commit -q -m "Set up a fresh Laravel app"',
214217
];
@@ -267,9 +270,11 @@ protected function pushToGitHub(string $name, string $directory, InputInterface
267270

268271
$flags = $input->getOption('github') ?: '--private';
269272

273+
$branch = $input->getOption('branch') ?: 'main';
274+
270275
$commands = [
271276
"gh repo create $name -y $flags",
272-
"git -c credential.helper= -c credential.helper='!gh auth git-credential' push -q -u origin main",
277+
"git -c credential.helper= -c credential.helper='!gh auth git-credential' push -q -u origin $branch",
273278
];
274279

275280
$this->runCommands($commands, $input, $output, ['GIT_TERMINAL_PROMPT' => 0]);

0 commit comments

Comments
 (0)