如何修改Git Bash的起始文件夹?修改‘Start in’属性无效求助
Fixing Git Bash's Default Startup Folder (When "Start in" Doesn't Work)
Hey there! I’ve run into this exact issue before—tweaking the Start in field in properties often doesn’t stick for Git Bash because it prioritizes its own shell configuration. Let me walk you through two reliable fixes that actually work:
Method 1: Modify the Git Bash Shortcut Target (Quick Per-Shortcut Fix)
This is great if you want a specific shortcut to open in your desired folder:
- Right-click your Git Bash shortcut and select Properties
- In the Target field, you’ll see something like:
"C:\Program Files\Git\git-bash.exe" - Append the
--cdflag with your target path (wrap the path in quotes if it has spaces):"C:\Program Files\Git\git-bash.exe" --cd="D:\Projects\MyRepo" - Click Apply then OK, then launch Git Bash again—it should open directly in your chosen folder.
Method 2: Edit Bash Configuration Files (Permanent Global Fix)
This makes Git Bash open in your target folder no matter which shortcut you use:
- Open Git Bash and run this command to find your home directory:
You’ll get a path likeecho $HOMEC:/Users/YourUsername(Git uses forward slashes here). - Navigate to that folder in File Explorer. If you don’t see hidden files, enable them (View > Show > Hidden items).
- Look for files named
.bash_profileor.bashrc. If neither exists, create a new text file named.bash_profile(make sure it doesn’t have a.txtsuffix—Windows might hide it by default, so double-check). - Open the file in a text editor and add this line (replace the path with your target folder, using forward slashes and the Git-style drive prefix like
/d/instead ofD:\):cd /d/Projects/MyRepo - Save the file, close Git Bash, and reopen it. It’ll now automatically navigate to your target folder on startup.
Quick Troubleshooting Tip
If you’re using a newer version of Git for Windows, your shortcut might already have a --cd parameter—just replace the existing path in that flag instead of adding a new one.
内容的提问来源于stack exchange,提问作者mtrobert
相关产品推荐
相关产品推荐

