Skip to content
Discussion options

You must be logged in to vote

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.sh

2. Update your prompt

Now modify your PS1 variable so it includes the current Git branch:

export PS1='\u@\h \w$(__git_ps1 " (%s)")\$ '

This will produce a prompt like:

user@machine MINGW64 ~/projects/myrepo (main)
$

Explanation:

  • \u → current user
  • \h → host name
  • \w → current working directory
  • __git_ps1 → prints the current Git…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@jev0a
Comment options

@jsoref
Comment options

Answer selected by jev0a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug GitHub or a GitHub feature is not working as intended other General topics and discussions that don't fit into other categories, but are related to GitHub
3 participants