git/list[1] front-page[2] threads[3] people[4] search[5] about
 

command prompt script for current branch

From
SSStephen Sinclair <radarsat1@gmail.com>
Date
Feb 6, 2008, 19:52 UTC
Message-ID
<9b3e2dc20802061152q63bc61acuaecf3f33d4df8b19@mail.gmail.com>
Hello,

Attached is a script I quickly wrote up yesterday. Sometimes I've found I started working only to realize I was on the wrong branch. (Now that I'm accustomed to working with git, I make many small branches, so it happens.)

So I made this small script to simply write the name of the currently checked out branch, as well as information on how many commits it differs from the remote tracking branch, if any. It also appends an exclamation mark if I have uncommitted changes. I stuck it in my PS1 environment variable, so that it would be part of my command prompt.

I tried to choose git commands that would be relatively quick, since this will be run for every single command prompt. If I've chosen suboptimal ways of doing this, please let me know. There's a few too many 'grep' and 'sed' commands for my liking, so maybe there is a way to get the same information more directly instead of parsing git command output. Anyways, if it's of general interest, I'd be happy to make a patch for /contrib.

For my tiny git repos, this seems to have pretty much no negative impact on my work flow. When I cd'd to my git.git clone there was about a 1/2-second delay the first time, but subsequent command prompts incurred no visible delay. I've no idea how fast it would be for something as big as the kernel, for example.

Steve
Next: Junio C Hamano
Message 1 of 16 in “command prompt script for current branch”
  1. Stephen SinclairFeb 6, 2008
  2. Junio C HamanoFeb 6, 2008
  3. Improve bash prompt to detect merge / rebase in progressRobin Rosenberg, Feb 6, 2008
  4. Robin RosenbergFeb 6, 2008
  5. Junio C HamanoFeb 6, 2008
  6. Robin RosenbergFeb 7, 2008
  7. Shawn O. PearceFeb 7, 2008
  8. Steffen ProhaskaFeb 8, 2008
  9. Johannes SchindelinFeb 8, 2008
  10. Steffen ProhaskaFeb 8, 2008
  11. Make git-completion.bash a first-class citizenJohannes Schindelin, Feb 8, 2008
  12. Jakub NarebskiFeb 6, 2008
  13. Mike HommeyFeb 6, 2008
  14. Jakub NarebskiFeb 6, 2008
  15. Stephen SinclairFeb 6, 2008
  16. Jakub NarebskiFeb 6, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.