Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

benlindsay commented Jan 8, 2016

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
You can’t perform that action at this time.