Use the Prompt, GIT!

Everybody who knows me knows I hate to run in circles. Suffering from a repetition syndrome is what awaits everyone who’s ignoring those nifty tricks that make their lives more convenient.

Over the course of years, I’ve met many people that use GIT too frequently to not have their setup include the convenience of a GIT prompt for their shell. To put things in perspective, this includes system administrators, but also software developers. Amazing, really. Astonishing, frankly.

Rather than convincing people individually through show-and-tell, and walking those people using the holding-hands-spelling-it-out “teaching” mechanism, and partly also because I promised in Part I of A Flask Mega-Tutorial, here’s how I set up mine.

Some might call it boring, but I’m a bash shell user, so you’ll need some or the other software package for bash completion, which in the world’s best distribution is called bash-completion.

In your ~/.bashrc, include the following snippet somewhere near the end (note this modifies your prompt only minimally compared to the default, and does precisely that on purpose):

Reload your ~/.bashrc by typing:

$ . ~/.bashrc

Yes, WordPress’s and/or this theme’s markup for preformatted text is the worst.

Now, here’s what I figured we would do:

  1. Create a GIT repository some place:Your prompt now shows a # character to indicate there’s a GIT repository, but nothing’s there yet.
  2. Let’s create an initial commit:Your prompt now shows a clean repository.
  3. Touch a file, add it, and commit it:Nothing too fancy there, but a % for untracked files, a + for newly tracked files not yet committed, and back to just the branch when it’s all good again.
  4. Add a remote, track it and fetch it:Having no commits in common is expected in this case, I just used one of the gists. I’m lazy like that 😉

    Note though how it indicates I’m ahead two commits, and behind one.

  5. Rebase on top of the tracking remote:And here we see we are +1 commit ahead of the remote branch we’re tracking. I’m not going to push this to keep my gist intact, but what I can do:
  6. Reset. Reset. Reset.And what I have = up-to-date with my tracking remote.