14 December 2015

Automatically updating git status when entering a directory in bash

We use Git and GitHub extensively in our work.

One of the biggest headaches we face is enforcing the discipline of checking the status of the master branch before edits are made in the local workspace.

To remedy this, we've overridden the functionality of the bash cd command to perform a remote update and then display the status.

Here's the relevant section from the .bashrc file:



# .bashrc

  # ...

  cd() {
    builtin cd "$@";
    if [ -e ".git" ]
    then
      git remote update &&  git status;
    fi
  }

No comments: