Skip to content

Configure Git Bash shell profiles during Windows install#522

Open
svarlamov wants to merge 2 commits intomainfrom
devin/1771029053-git-bash-windows-support
Open

Configure Git Bash shell profiles during Windows install#522
svarlamov wants to merge 2 commits intomainfrom
devin/1771029053-git-bash-windows-support

Conversation

@svarlamov
Copy link
Member

@svarlamov svarlamov commented Feb 14, 2026

Configure Git Bash shell profiles during Windows install

Summary

Fixes #517. Git Bash (MSYS2/MinGW) prepends /mingw64/bin to PATH during its own shell initialization, which shadows the git-ai shim even when the Windows PATH has been correctly set by Set-PathPrependBeforeGit. This adds a new section to install.ps1 that writes export PATH="$HOME/.git-ai/bin:$PATH" into the user's ~/.bashrc or ~/.bash_profile, mirroring what install.sh already does for Unix shells.

The new block:

  1. Detects Git for Windows by checking common install paths (Program Files, Program Files (x86), LocalAppData\Programs)
  2. Finds existing .bashrc or .bash_profile (or creates .bashrc if neither exists)
  3. Checks for an existing .git-ai/bin marker to avoid duplicate entries
  4. Appends the PATH export if not already present
  5. Wraps everything in try/catch so a failure here never blocks the rest of the install

Updates since last revision

  • Fixed UTF-8 BOM issue flagged by Devin Review: replaced Add-Content -Encoding UTF8 with [System.IO.File]::AppendAllText() using UTF8Encoding($false) to avoid writing a BOM that would cause command not found errors in bash on PowerShell 5.1.

Review & Testing Checklist for Human

  • Test on a real Windows machine with Git Bash installed — this change is entirely in PowerShell and cannot be verified by the Rust test suite or Linux CI. Run the installer, then open Git Bash and confirm which git resolves to ~/.git-ai/bin/git (not /mingw64/bin/git)
  • Verify no UTF-8 BOM in created .bashrc — the code now uses UTF8Encoding($false) + AppendAllText, but confirm the written file has no BOM bytes (EF BB BF) at the start, especially when .bashrc is newly created (no pre-existing file)
  • Test idempotency — run the installer twice and confirm the PATH export is not duplicated in .bashrc
  • Test with no existing .bashrc — confirm the installer creates .bashrc and the export line is correct. Consider whether creating .bashrc when a user has never used Git Bash is desirable, or if this should only append to existing files

Notes

  • Git Bash detection only covers standard Git for Windows install paths. Custom locations (Scoop, Chocolatey portable, etc.) won't be detected, but the code simply skips configuration in that case — no harm done.
  • Link to Devin run
  • Requested by @svarlamov

Git Bash (MSYS2/MinGW) prepends /mingw64/bin to PATH during shell
initialization, which shadows the git-ai shim even when the Windows
PATH has been correctly configured. Fix this by detecting Git for
Windows installations and writing an export PATH line to ~/.bashrc
or ~/.bash_profile, mirroring what install.sh already does for Unix
shells.

Closes #517

Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@git-ai-cloud-dev
Copy link

No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

devin-ai-integration[bot]

This comment was marked as resolved.

@svarlamov
Copy link
Member Author

review devin feedback

PowerShell 5.1's Add-Content -Encoding UTF8 writes a UTF-8 BOM that
causes 'command not found' errors in bash. Use .NET's
UTF8Encoding(false) + AppendAllText instead to avoid the BOM.

Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 8 additional findings in Devin Review.

Open in Devin Review

Comment on lines +451 to +455
$gitForWindowsPaths = @(
(Join-Path $env:ProgramFiles 'Git\bin\bash.exe'),
(Join-Path ${env:ProgramFiles(x86)} 'Git\bin\bash.exe'),
(Join-Path $env:LOCALAPPDATA 'Programs\Git\bin\bash.exe')
)
Copy link
Contributor

Choose a reason for hiding this comment

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

🟡 Eager Join-Path evaluation with null env var aborts entire Git Bash config block

If ${env:ProgramFiles(x86)} is $null (e.g., on 32-bit Windows), the Join-Path call on line 453 throws a ParameterBindingValidationException during array construction, before the loop on line 456 ever executes. This causes the entire try block to jump to catch, skipping Git Bash configuration entirely — even if Git Bash is installed at one of the other checked paths ($env:ProgramFiles\Git\bin\bash.exe or $env:LOCALAPPDATA\Programs\Git\bin\bash.exe).

Root Cause

All three Join-Path calls on lines 452-454 are evaluated eagerly when constructing the $gitForWindowsPaths array. The null-guard $p -and on line 457 was intended to handle null paths, but it never gets reached because the exception occurs during array initialization.

$gitForWindowsPaths = @(
    (Join-Path $env:ProgramFiles 'Git\bin\bash.exe'),
    (Join-Path ${env:ProgramFiles(x86)} 'Git\bin\bash.exe'),  # throws if null
    (Join-Path $env:LOCALAPPDATA 'Programs\Git\bin\bash.exe')
)

With Set-StrictMode -Version Latest (line 2), Join-Path with a $null -Path parameter throws a terminating error. The fix is to guard each path construction against null, e.g., by only adding non-null paths to the array, or by using if checks before Join-Path.

Impact: On 32-bit Windows (rare but possible), Git Bash shell profile configuration is silently skipped with only a warning message, even when Git Bash is installed.

Suggested change
$gitForWindowsPaths = @(
(Join-Path $env:ProgramFiles 'Git\bin\bash.exe'),
(Join-Path ${env:ProgramFiles(x86)} 'Git\bin\bash.exe'),
(Join-Path $env:LOCALAPPDATA 'Programs\Git\bin\bash.exe')
)
$gitForWindowsPaths = @()
if ($env:ProgramFiles) { $gitForWindowsPaths += Join-Path $env:ProgramFiles 'Git\bin\bash.exe' }
if (${env:ProgramFiles(x86)}) { $gitForWindowsPaths += Join-Path ${env:ProgramFiles(x86)} 'Git\bin\bash.exe' }
if ($env:LOCALAPPDATA) { $gitForWindowsPaths += Join-Path $env:LOCALAPPDATA 'Programs\Git\bin\bash.exe' }
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure Git AI properly tracks git events from Windows git bash

2 participants