打开Git Bash时出现__gitps1: command not found错误求助
__gitps1: command not found Error in Git Bash Hey Mark, let’s get your Git Bash up and running again—this error is super common once you know what’s going on, and we can fix it in a few minutes.
What’s causing this?
The __gitps1 function is what Git uses to show your current Git branch in the Bash prompt. The error pops up because your Bash configuration is trying to call this function, but it hasn’t been loaded properly (usually because the Git prompt script isn’t being sourced automatically). Uninstalling/reinstalling Git often doesn’t fix this because your user-specific Bash config files (like .bashrc) aren’t deleted during uninstall.
Step 1: Get Git Bash working immediately
Open Git Bash, and run this command first to manually load the Git prompt script (adjust the path if you installed Git in a different location):
. "/c/Program Files/Git/mingw64/share/git/completion/git-prompt.sh"
You should now be able to run all Git commands, including generating SSH keys with ssh-keygen -t ed25519 -C "your_email@example.com".
Step 2: Fix the error permanently
To make sure this doesn’t happen every time you open Git Bash:
- In Git Bash, open your
.bashrcfile (create it if it doesn’t exist) with:nano ~/.bashrc - Paste these two lines at the end of the file (again, adjust the path if your Git install is in a different folder, e.g.,
Program Files (x86)for 32-bit Git):source "/c/Program Files/Git/mingw64/share/git/completion/git-prompt.sh" source "/c/Program Files/Git/mingw64/share/git/completion/git-completion.bash" - Save the file (in nano, press
Ctrl+O, thenEnter, thenCtrl+Xto exit). - Close and reopen Git Bash—the error should be gone, and you’ll see your Git branch in the prompt if you’re in a repo.
Bonus: Generate SSH keys with Git CMD right now
Since you mentioned Git CMD works fine, you can generate your SSH key immediately using it too:
- Open Git CMD.
- Run:
ssh-keygen -t ed25519 -C "your_email@example.com" - Follow the prompts (you can press Enter to accept default locations and passphrases). The key will be saved in
C:\Users\your_username\.ssh—same as if you used Git Bash.
内容的提问来源于stack exchange,提问作者Mark Druffel




