Skip to content

Instantly share code, notes, and snippets.

@gre
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gre/11da8bd3e974ee480878 to your computer and use it in GitHub Desktop.
Save gre/11da8bd3e974ee480878 to your computer and use it in GitHub Desktop.
resolve git config contextually (find a .gitconfig in the PWD tree)
#!/bin/bash
# Put this script in ~/bin/git.sh and `chmod +x` it
# in your .bash_profile add: alias git=$HOME/bin/git.sh
###### DO NOT USE IT #####
##### it doesn't seem to work properly... git commit still put the wrong git config even if git config say something else ######
function upsearch () {
slashes=${PWD//[^\/]/}
directory="$PWD"
for (( n=${#slashes}; n>0; --n ))
do
test -e "$directory/$1" && echo "$directory/$1" && return
directory="$directory/.."
done
}
GIT_CONFIG=`upsearch .gitconfig` git $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment