Skip to content

Instantly share code, notes, and snippets.

@chhh
Last active August 16, 2018 23:43
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 chhh/c4afa4de33d4239b5cbe928a9f969bf6 to your computer and use it in GitHub Desktop.
Save chhh/c4afa4de33d4239b5cbe928a9f969bf6 to your computer and use it in GitHub Desktop.
Create git repositories in all leaf directories. Useful for setting up large multi-project builds with Gradle, for example.
#!/bin/bash
startdir=`pwd`
# # find all the LEAF directories that don't have .git somewhere along the path
# selection of LEAFs is done in the awk part
# the output of find is read line by line, assuming filenames don't have newlines
# `find -print0` wouldn't work, as this would screw up the awk part
find . -not \( -name .git -prune \) -type d -print | sort -r | awk 'a!~"^"$0{a=$0;print}' | sort | while read -d $'\n' file
do
echo "Going to -> $file"
cd $file
echo "In: `pwd`"
if [ ! -d ".git" ]; then
echo "Initializing a new git repo"
git init
git add -A
git cm "Init commit"
else
echo "Already a git repo, skipping"
fi
echo "Going back to start directory"
cd $startdir
echo "----------"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment