Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env sh
# subgit
# A tiny wrapper around git to help you manage
# Git sub-projects easily, safely, and simply.
# Created by Rusty Klophaus (@rklophaus)
# See for usage.
if [ "$1" == "setup" ]; then
if [ -d ".git" ]; then
mv .git .subgit
echo "Converted to a subgit repository."
exit 0
echo "Could not find .git directory."
exit -1
while [ ! -d "$DIR/.subgit" ] && [ ! "$DIR" == "/" ]; do
DIR=`dirname $DIR`
if [ $DIR == "/" ]; then
echo "Not in a subgit repository!"
exit -1
git --git-dir=$DIR/.subgit "$@"

This comment has been minimized.

sharat87 commented Nov 25, 2010

Thanks for the script, really needed it :)

Just one thing, it does not work for me on Ubuntu 10.04 unless I change the shebang line to use bash instead of sh. Thought you might want to know :)


This comment has been minimized.

Feh commented Nov 14, 2011

If you remove the "==" bashism, it'll work in any POSIX shell (like Dash).


This comment has been minimized.

assumptionsoup commented Apr 7, 2014

Does anyone know a way to get bash tab completion to work with this? I've been trying to get it to work for a while now with no success.


This comment has been minimized.

johnilacqua commented Feb 28, 2017

For anyone who wants to use this script, I'd recommend changing line 33 to
git --git-dir="$DIR/.subgit" --work-tree="$DIR" "$@"
otherwise it doesn't work properly if you're in a subdirectory within the subgit repo.

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