Linux

Never miss a branch again

When working with a git repository you need to know which branch you are committing to. To do that you type git status and check for the info. Sometimes you just need to know the branch in order not to make mistakes when merging. It is super useful to have branch name as part of the command prompt.

Jim Myhrberg created a repository on GitHub with code and instructions on how to achieve this: https://github.com/jimeh/git-aware-prompt

Instructions for installation are pretty simple and work quite well out of the box.

There are a lot of forks of this repository. Specially interesting is this one by Paul “Joey” Clark: https://github.com/joeytwiddle/git-aware-prompt 

  • shows you how far your local branch is ahead or behind the repository’s branch
  • shows how many files are staged
  • indicates when you have an un-popped stash (when the top stash entry was made on the current commit or the current branch)
  • displays when you are on a detached commit, or paused during a merge, rebase or cherry-pick
  • adds a timeout for slower machines so that you will get your prompt quickly, even if git status is taking too long to retrieve the dirty and staged stats.

In the end, you are left with branch name in your prompt:

Or, like this if you used joeytwiddle’s repository:

 

Recent Posts

Sonata Admin: modify validation groups in an admin extension

SonataAdminBundle has a powerful extensions feature which allows you to add or change features of…

3 years ago

Grandfather’s advices

I used to spend a lot of time with my grandparents in my childhood. My…

5 years ago

World. World never stops changing.

If anything is certain in this world, it is that things always change. And there…

5 years ago

How to be successful

This is the most important advice on how to be successful! Read it carefully!

8 years ago

I wanted to change WordPress URL, you won’t believe what happened afterwards

WordPress has a nasty habit of storing absolute URLs in the database. That means that…

8 years ago

Let’s Encrypt – providing free automated SSL certificates

In August 2014 Google announced that their search engine will value HTTPS as a ranking…

9 years ago