@@ -53,6 +53,7 @@ func Run() {
5353 ui .Header ("Git Genius Setup" )
5454
5555 cfg := config .Load ()
56+ origCwd , _ := os .Getwd ()
5657 // #region agent log
5758 debugLog ("pre-fix" , "H1" , "internal/setup/setup.go:Run" , "setup started" , map [string ]interface {}{
5859 "initialWorkDir" : cfg .WorkDir ,
@@ -68,6 +69,12 @@ func Run() {
6869 // #endregion
6970 return
7071 }
72+ // Keep config + error logs synchronized with the chosen workdir.
73+ // These codepaths use relative paths like ".git/.genius".
74+ if cfg .WorkDir != "" {
75+ _ = os .Chdir (cfg .WorkDir )
76+ defer func () { _ = os .Chdir (origCwd ) }()
77+ }
7178 config .Save (cfg )
7279 // #region agent log
7380 debugLog ("pre-fix" , "H1" , "internal/setup/setup.go:Run" , "workdir saved" , map [string ]interface {}{
@@ -295,16 +302,24 @@ func setupGitHubToken() bool {
295302///////////////////////////////////////////////////////////////
296303
297304func ensureGitHubRepo (cfg * config.Config ) {
305+ // Best-effort existence check to avoid noisy 422 errors.
306+ exists , err := github .RepoExists (cfg .Owner , cfg .Repo )
307+ if err == nil && exists {
308+ ui .Success ("GitHub repository already exists" )
309+ return
310+ }
311+
312+ // If verification failed, fall back to user-driven create flow.
298313 if ! ui .Confirm ("Create repository on GitHub if not exists?" ) {
299314 return
300315 }
301316
302317 private := ui .Confirm ("Make repository PRIVATE?" )
303318
304- err := github .CreateRepo (cfg .Owner , cfg .Repo , private )
305- if err != nil {
319+ createErr := github .CreateRepo (cfg .Owner , cfg .Repo , private )
320+ if createErr != nil {
306321 ui .Warn ("Repository creation failed:" )
307- ui .Info (err .Error ())
322+ ui .Info (createErr .Error ())
308323 return
309324 }
310325
@@ -357,8 +372,23 @@ func offerFirstPush(cfg *config.Config) {
357372 return
358373 }
359374
360- // Commit may fail if nothing to commit
361- _ = system .RunGit ("commit" , "-m" , msg )
375+ // Avoid pushing without a real first commit.
376+ // Common case: empty repo => "nothing to commit" after `git add .`.
377+ stagedNames , err := system .GitOutput ("diff" , "--cached" , "--name-only" )
378+ if err != nil {
379+ ui .Error ("Failed to check staged changes" )
380+ return
381+ }
382+ if stagedNames == "" {
383+ ui .Warn ("Nothing to commit yet (working tree is empty)" )
384+ ui .Info ("Add at least one file, then push again." )
385+ return
386+ }
387+
388+ if err := system .RunGit ("commit" , "-m" , msg ); err != nil {
389+ ui .Error ("Initial commit failed" )
390+ return
391+ }
362392
363393 branch := system .CurrentGitBranch ()
364394 if branch == "" {
0 commit comments