Skip to content

Instantly share code, notes, and snippets.

@bobthecow
Created April 29, 2010 15:45
Show Gist options
  • Select an option

  • Save bobthecow/383792 to your computer and use it in GitHub Desktop.

Select an option

Save bobthecow/383792 to your computer and use it in GitHub Desktop.
cd relative to the current Git repo
#!/bin/bash
#
# cd relative to the current Git repo
#
# Author: Justin Hileman (http://justinhileman.com)
#
# Installation:
# Add the following function to your `.bashrc` or `.bash_profile`,
# or save it somewhere (e.g. `~/.cdg.bash`) and source it in `.bashrc`
#
# Usage:
# cdg [path relative to git dir]
cdg () {
[[ ! -z $(which git 2> /dev/null) ]] && [[ $(git status 2> /dev/null) ]] && cd "./$(git rev-parse --show-cdup)/$1"
}
@benlindsay
Copy link
Copy Markdown

Awesome! Works perfectly, and super short. Thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment