Skip to content

fix(server): Use 'main' as default branch for new git projects#744

Merged
Shironex merged 1 commit intov0.14.0rcfrom
fix/git-project-initial-branch
Feb 2, 2026
Merged

fix(server): Use 'main' as default branch for new git projects#744
Shironex merged 1 commit intov0.14.0rcfrom
fix/git-project-initial-branch

Conversation

@Shironex
Copy link
Copy Markdown
Collaborator

@Shironex Shironex commented Feb 2, 2026

Git initialization now explicitly specifies --initial-branch=main to match GitHub's default branch standard (since October 2020). This prevents the branch name mismatch that caused features to disappear from the UI when pushing to GitHub.

Fixes #734

Summary by CodeRabbit

  • Bug Fixes
    • Git repositories now initialize with 'main' as the default branch name, ensuring consistency across repository creation and initialization workflows.

Git initialization now explicitly specifies --initial-branch=main to match
GitHub's default branch standard (since October 2020). This prevents the
branch name mismatch that caused features to disappear from the UI when
pushing to GitHub.

Fixes #734

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Shironex Shironex self-assigned this Feb 2, 2026
@Shironex Shironex added Testers-Requested Request for others to test an enhancement or bug fix/etc. Do Not Merge Use this label if something should not be merged. labels Feb 2, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Shironex, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where newly initialized Git projects by the server would not use 'main' as their default branch, leading to inconsistencies and potential UI problems when interacting with platforms like GitHub. By modifying the git init command to include --initial-branch=main, the system now ensures that all new repositories are created with the correct default branch from the outset, improving compatibility and user experience.

Highlights

  • Default Branch Initialization: The server-side Git initialization process now explicitly uses main as the default branch for new projects, aligning with GitHub's current standard.
  • Integration Test Updates: All relevant integration tests for Git repository creation have been updated to also initialize repositories with main as the default branch.
  • Code Simplification: A redundant git branch -M main command in the test helper has been removed, as the initial branch is now correctly set during git init.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 2, 2026

📝 Walkthrough

Walkthrough

The PR updates git initialization commands across the application and tests to use the --initial-branch=main flag, ensuring newly created projects default to the 'main' branch instead of 'master', aligning with modern GitHub standards.

Changes

Cohort / File(s) Summary
Git Initialization Routes
apps/server/src/routes/worktree/routes/init-git.ts
Added --initial-branch=main flag to git init command to explicitly set the default branch to main for new projects.
Test Infrastructure
apps/server/tests/integration/helpers/git-test-repo.ts, apps/server/tests/integration/routes/worktree/create.integration.test.ts
Updated test setup to use git init --initial-branch=main, removing redundant git branch -M main step in helper and adding clarifying comment in integration test.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Hopping through the git tree with glee,
No more "master" in our warren you see,
We've planted our flag on "main" with care,
Every branch now grows with GitHub flair,
Default-branch harmony, what a delight,
Our burrows of code are organized right! 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: using 'main' as the default branch for new git projects, which is the primary objective of this PR.
Linked Issues check ✅ Passed The PR successfully implements the suggested fix from issue #734 by adding --initial-branch=main to git init commands across all three files that handle git initialization.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue #734; three files were modified to consistently use git init --initial-branch=main without introducing any unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/git-project-initial-branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly standardizes the default branch to 'main' for new git projects, which is a good improvement. My review focuses on a potential compatibility issue with the chosen implementation. The use of git init --initial-branch=main is not supported on Git versions prior to 2.28.0, which could lead to failures for users with older installations. I have provided suggestions to use a more widely compatible command sequence that achieves the same result, ensuring the feature is robust across different environments.

Comment on lines +48 to +53
await execAsync(
`git init --initial-branch=main && git commit --allow-empty -m "Initial commit"`,
{
cwd: projectPath,
}
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The --initial-branch flag for git init was introduced in Git v2.28.0. This command will fail for users with older versions of Git, breaking the repository initialization feature. For better compatibility, it's safer to use a command sequence that works on older versions as well.

Suggested change
await execAsync(
`git init --initial-branch=main && git commit --allow-empty -m "Initial commit"`,
{
cwd: projectPath,
}
);
await execAsync(
`git init && git checkout -b main && git commit --allow-empty -m "Initial commit"`,
{
cwd: projectPath,
}
);

// Initialize git repo
await execAsync('git init', { cwd: tmpDir });
// Initialize git repo with 'main' as the default branch (matching GitHub's standard)
await execAsync('git init --initial-branch=main', { cwd: tmpDir });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using git init --initial-branch=main could cause test failures in environments with older Git versions (< 2.28.0). To improve test stability and consistency with the application code, a more compatible approach is recommended.

Suggested change
await execAsync('git init --initial-branch=main', { cwd: tmpDir });
await execAsync('git init && git checkout -b main', { cwd: tmpDir });

repoPath = await fs.mkdtemp(path.join(os.tmpdir(), 'automaker-no-commit-'));
await execAsync('git init', { cwd: repoPath });
// Initialize with 'main' as the default branch (matching GitHub's standard)
await execAsync('git init --initial-branch=main', { cwd: repoPath });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To ensure tests are reliable across different development and CI environments, it's best to avoid commands that depend on a recent Git version. The --initial-branch flag is not universally available and could lead to test failures.

Suggested change
await execAsync('git init --initial-branch=main', { cwd: repoPath });
await execAsync('git init && git checkout -b main', { cwd: repoPath });

@Shironex Shironex merged commit 29b3eef into v0.14.0rc Feb 2, 2026
9 of 10 checks passed
@Shironex Shironex deleted the fix/git-project-initial-branch branch February 2, 2026 14:20
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/server/src/routes/worktree/routes/init-git.ts`:
- Around line 46-53: The current git init code uses execAsync with
--initial-branch (incompatible with Git <2.28) and bypasses established
patterns; replace this with a delegated service that uses execGitCommand() from
common.ts and the ensureInitialCommit() helper (or fallback to git init + git
branch -M main) to create the initial commit, call isGitRepo() from
`@automaker/git-utils` to verify repository state, and emit progress/events via
createEventEmitter() consistent with create.ts so the route delegates to that
service rather than running raw shell commands.
🧹 Nitpick comments (1)
apps/server/src/routes/worktree/routes/init-git.ts (1)

46-53: Consider extracting git-init into a service and emitting events.

This route executes business logic directly and doesn’t emit any events; moving the git-init flow into a service and emitting start/success/failure events would align with the server architecture expectations.

As per coding guidelines, Server business logic should be organized into services in the services/ directory, with Express route handlers in routes/ that delegate to services; and All server operations should emit events using createEventEmitter() from lib/events.ts that stream to the frontend via WebSocket.

Comment on lines +46 to +53
// Initialize git with 'main' as the default branch (matching GitHub's standard since 2020)
// and create an initial empty commit
await execAsync(
`git init --initial-branch=main && git commit --allow-empty -m "Initial commit"`,
{
cwd: projectPath,
}
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the file structure and the specific file mentioned
fd -t f "init-git.ts" --full-path

Repository: AutoMaker-Org/automaker

Length of output: 117


🏁 Script executed:

# Search for documented Git version requirements in the repo
rg -n "minimum git|git>=|git version|git 2\." --type-list | head -20
rg -i "git.*version\|version.*git" . -A 2 -B 2 | head -50

Repository: AutoMaker-Org/automaker

Length of output: 456


🏁 Script executed:

# Check if `@automaker/git-utils` package exists and explore the codebase
fd -t d "@automaker" . | head -20

Repository: AutoMaker-Org/automaker

Length of output: 49


🏁 Script executed:

# Look for any CI configuration that might specify Git version
fd -t f -e yml -e yaml -e json . | grep -E "(\.github|\.gitlab|azure|workflow|ci|package)" | head -20

Repository: AutoMaker-Org/automaker

Length of output: 613


🏁 Script executed:

# Read the specific file to see the full context
cat -n apps/server/src/routes/worktree/routes/init-git.ts

Repository: AutoMaker-Org/automaker

Length of output: 2367


🏁 Script executed:

# Check the git-utils module to see what's available
cat libs/git-utils/package.json

Repository: AutoMaker-Org/automaker

Length of output: 761


🏁 Script executed:

# Look for git-utils index/main exports
fd -t f "index\|main" libs/git-utils --full-path | head -10

Repository: AutoMaker-Org/automaker

Length of output: 49


🏁 Script executed:

# Search for Git version constraints in package.json, CI configs
cat package.json | grep -i git

Repository: AutoMaker-Org/automaker

Length of output: 371


🏁 Script executed:

# Check for CI workflows
fd -t f "\.github" . --full-path | head -20

Repository: AutoMaker-Org/automaker

Length of output: 49


🏁 Script executed:

# Find git-utils source files
fd -t f . libs/git-utils --full-path | head -20

Repository: AutoMaker-Org/automaker

Length of output: 326


🏁 Script executed:

# Check services directory pattern in server
ls -la apps/server/src/ | grep -i service
fd -t d "services" apps/server/src/ --full-path

Repository: AutoMaker-Org/automaker

Length of output: 152


🏁 Script executed:

# Look for event emitter usage in the server
rg "createEventEmitter\|EventEmitter" apps/server/src/ -l

Repository: AutoMaker-Org/automaker

Length of output: 49


🏁 Script executed:

# Search for git version constraints in any documentation or code
rg "git.*2\.28\|git.*version" . -i | head -20

Repository: AutoMaker-Org/automaker

Length of output: 49


🏁 Script executed:

# Read git-utils index to see available exports
cat libs/git-utils/src/index.ts

Repository: AutoMaker-Org/automaker

Length of output: 542


🏁 Script executed:

# List what services exist
ls -la apps/server/src/services/

Repository: AutoMaker-Org/automaker

Length of output: 1734


🏁 Script executed:

# Read a service file to understand the pattern
fd -t f . apps/server/src/services/ | head -3

Repository: AutoMaker-Org/automaker

Length of output: 203


🏁 Script executed:

# Check git-utils status and diff to understand what it provides
cat libs/git-utils/src/status.ts | head -50

Repository: AutoMaker-Org/automaker

Length of output: 1403


🏁 Script executed:

# Check if there's any git init related function in git-utils
rg "init\|branch" libs/git-utils/src/ -i

Repository: AutoMaker-Org/automaker

Length of output: 49


🏁 Script executed:

# Look at an example service to understand the pattern
head -100 apps/server/src/services/event-history-service.ts

Repository: AutoMaker-Org/automaker

Length of output: 2789


🏁 Script executed:

# Check if there's a lib/events.ts mentioned in guidelines
cat apps/server/src/lib/events.ts 2>/dev/null | head -50

Repository: AutoMaker-Org/automaker

Length of output: 1041


🏁 Script executed:

# Check other routes to see the pattern - do they use services?
ls -la apps/server/src/routes/

Repository: AutoMaker-Org/automaker

Length of output: 1909


🏁 Script executed:

# Check the git routes structure
ls -la apps/server/src/routes/git/

Repository: AutoMaker-Org/automaker

Length of output: 350


🏁 Script executed:

# Check if there's a git service
ls -la apps/server/src/services/git/ 2>/dev/null || echo "No git service found"

Repository: AutoMaker-Org/automaker

Length of output: 87


🏁 Script executed:

# Look at how other routes use services - pick a simpler one
cat apps/server/src/routes/health/routes/check.ts | head -50

Repository: AutoMaker-Org/automaker

Length of output: 144


🏁 Script executed:

# Check if worktree routes use services
ls -la apps/server/src/routes/worktree/

Repository: AutoMaker-Org/automaker

Length of output: 420


🏁 Script executed:

# List worktree routes
ls -la apps/server/src/routes/worktree/routes/

Repository: AutoMaker-Org/automaker

Length of output: 2288


🏁 Script executed:

# Check the common.ts file in worktree
cat apps/server/src/routes/worktree/common.ts

Repository: AutoMaker-Org/automaker

Length of output: 7047


🏁 Script executed:

# Check another route to see if services are used
cat apps/server/src/routes/worktree/routes/create.ts | head -80

Repository: AutoMaker-Org/automaker

Length of output: 2844


🏁 Script executed:

# Search for where createEventEmitter is being used in the codebase
rg "createEventEmitter" apps/server/src/ -A 3 | head -60

Repository: AutoMaker-Org/automaker

Length of output: 887


Refactor to follow established patterns and support older Git versions.

This route should follow the architectural patterns established in create.ts:

  1. Git version compatibility: --initial-branch requires Git >= 2.28. Use the ensureInitialCommit() helper from common.ts (which already exists) or implement a fallback with git init + git branch -M main.

  2. Code quality: Replace raw execAsync shell commands with execGitCommand() from common.ts for safe, array-based argument passing (prevents injection).

  3. Architecture: Following create.ts, this route should delegate to a service, emit events via createEventEmitter(), and use @automaker/git-utils where applicable (e.g., isGitRepo()).

Consider delegating git initialization to a service that emits progress events to the frontend, consistent with other worktree operations.

🤖 Prompt for AI Agents
In `@apps/server/src/routes/worktree/routes/init-git.ts` around lines 46 - 53, The
current git init code uses execAsync with --initial-branch (incompatible with
Git <2.28) and bypasses established patterns; replace this with a delegated
service that uses execGitCommand() from common.ts and the ensureInitialCommit()
helper (or fallback to git init + git branch -M main) to create the initial
commit, call isGitRepo() from `@automaker/git-utils` to verify repository state,
and emit progress/events via createEventEmitter() consistent with create.ts so
the route delegates to that service rather than running raw shell commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Do Not Merge Use this label if something should not be merged. Testers-Requested Request for others to test an enhancement or bug fix/etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant