-
|
I’m using Git Bash on Windows and would really appreciate it if I could customize the terminal prompt to display the current Git branch whenever I’m in a repository. Currently, my prompt just shows the current directory, like this: user@machine MINGW64 ~/projects/myrepo I’m hoping for something like: user@machine MINGW64 ~/projects/myrepo (main) I’ve looked into tools like oh-my-posh or starship, but I’m not sure which one is easiest to get working with Git Bash. Do you have any ideas on how to set this up using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
💬 Your Product Feedback Has Been Submitted 🎉 Thank you for taking the time to share your insights with us! Your feedback is invaluable as we build a better GitHub experience for all our users. Here's what you can expect moving forward ⏩
Where to look to see what's shipping 👀
What you can do in the meantime 💻
As a member of the GitHub community, your participation is essential. While we can't promise that every suggestion will be implemented, we want to emphasize that your feedback is instrumental in guiding our decisions and priorities. Thank you once again for your contribution to making GitHub even better! We're grateful for your ongoing support and collaboration in shaping the future of our platform. ⭐ |
Beta Was this translation helpful? Give feedback.
-
|
You can achieve this in Git Bash on Windows without installing tools like oh-my-posh or starship. Git already ships with a helper script that exposes the current branch for use in your prompt. 1. Enable Git's prompt helperGit for Windows includes a script called source /usr/share/git/completion/git-prompt.sh2. Update your promptNow modify your export PS1='\u@\h \w$(__git_ps1 " (%s)")\$ 'This will produce a prompt like: Explanation:
If you're not inside a Git repository, the branch part simply won't appear. 3. Reload your shellApply the changes: source ~/.bashrcOptional: show repository statusGit also supports additional indicators such as dirty state or upstream tracking: export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWUPSTREAM=autoThis can display markers showing if the working directory has changes or if the branch is ahead/behind its upstream. This approach works well with the default Git Bash (MINGW64) environment and avoids installing extra prompt frameworks unless you specifically want more advanced customization. |
Beta Was this translation helpful? Give feedback.
You can achieve this in Git Bash on Windows without installing tools like oh-my-posh or starship. Git already ships with a helper script that exposes the current branch for use in your prompt.
1. Enable Git's prompt helper
Git for Windows includes a script called
git-prompt.sh. Add the following line to your~/.bashrc:source /usr/share/git/completion/git-prompt.sh2. Update your prompt
Now modify your
PS1variable so it includes the current Git branch:This will produce a prompt like:
Explanation:
\u→ current user\h→ host name\w→ current working directory__git_ps1→ prints the current Git…