diff --git a/pkg/app/app.go b/pkg/app/app.go index a5a241ac5..9a7b1ffcc 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -173,12 +173,20 @@ func (app *App) setupRepo() (bool, error) { shouldInitRepo := true notARepository := app.UserConfig.NotARepository + initialBranch := "" if notARepository == "prompt" { // Offer to initialize a new repository in current directory. fmt.Print(app.Tr.CreateRepo) response, _ := bufio.NewReader(os.Stdin).ReadString('\n') if strings.Trim(response, " \r\n") != "y" { shouldInitRepo = false + } else { + // Ask for the initial branch name + fmt.Print(app.Tr.InitialBranch) + response, _ := bufio.NewReader(os.Stdin).ReadString('\n') + if trimmedResponse := strings.Trim(response, " \r\n"); len(trimmedResponse) > 0 { + initialBranch += "--initial-branch=" + trimmedResponse + } } } else if notARepository == "skip" { shouldInitRepo = false @@ -197,7 +205,7 @@ func (app *App) setupRepo() (bool, error) { fmt.Println(app.Tr.NoRecentRepositories) os.Exit(1) } - if err := app.OSCommand.Cmd.New("git init").Run(); err != nil { + if err := app.OSCommand.Cmd.New("git init " + initialBranch).Run(); err != nil { return false, err } } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 975cc9285..4f5b4eb48 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -258,6 +258,7 @@ type TranslationSet struct { DiscardFileChangesPrompt string DisabledForGPG string CreateRepo string + InitialBranch string NoRecentRepositories string AutoStashTitle string AutoStashPrompt string @@ -884,6 +885,7 @@ func EnglishTranslationSet() TranslationSet { DiscardFileChangesPrompt: "Are you sure you want to discard this commit's changes to this file? If this file was created in this commit, it will be deleted", DisabledForGPG: "Feature not available for users using GPG", CreateRepo: "Not in a git repository. Create a new git repository? (y/n): ", + InitialBranch: "Branch name? (leave empty for git's default): ", NoRecentRepositories: "Must open lazygit in a git repository. No valid recent repositories. Exiting.", AutoStashTitle: "Autostash?", AutoStashPrompt: "You must stash and pop your changes to bring them across. Do this automatically? (enter/esc)",