The outline command is partly correct and mostly not, but can be made correct enough.
You have:
cd folder-with-all-folders-to-git-init
for D in `find . -type d`
do
git init && git add . && git commit -m "Initial commit"
done
At minimum, you need to cd
into each directory before running git init
. That should be done like:
cd folder-with-all-folders-to-git-init
for D in `find . -type d`
do
(cd "$D" && git init && git add . && git commit -m "Initial commit")
done
This launches a subshell which avoids problems with symlinks and getting back to where you started.
Using back-quotes is not recommended; use the $( … )
notation instead. But reading names from that result is also not a good idea if there could be spaces in the names. You'd do best with a 'glob'. It might also be worth testing for the absence of a .git
subdirectory before trying to do git init
, especially if you have to run the script multiple times. Also, the find
will find sub-directories, such as existing .git
sub-directories.
That leads to:
cd folder-with-all-folders-to-git-init
for D in *
do
if [ -d "$D" ] && [ ! -d "$D/.git" ]
then (cd "$D" && git init && git add . && git commit -m "Initial commit")
fi
done
This is a reasonably robust solution to the problem. If there really are nested directories that you want to make into independent Git repositories, you'll need to work a bit harder, but that probably isn't what you want.