Skip to content

Instantly share code, notes, and snippets.

@jpeak5
Last active October 27, 2017 14:46
Show Gist options
  • Select an option

  • Save jpeak5/920a966b3b8247ee0d7dd9ad3322cda9 to your computer and use it in GitHub Desktop.

Select an option

Save jpeak5/920a966b3b8247ee0d7dd9ad3322cda9 to your computer and use it in GitHub Desktop.
bash script for getting the version of all git repos under $1
#!/bin/bash
## thanks to
# https://askubuntu.com/questions/429229/how-to-check-in-a-bash-script-if-passed-argument-is-file-or-directory
# https://stackoverflow.com/questions/5311956/bash-remove-first-directory-component-from-variable-path-of-file
# https://stackoverflow.com/questions/11981716/how-to-quickly-find-all-git-repos-under-a-directory
# https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find
# https://stackoverflow.com/questions/949314/how-to-retrieve-the-hash-for-the-current-commit-in-git
root=$1
for d in $(find $root -type d -name '.git'); do
if [ -d $d ]
then
cd $d/..
wkdir=$(pwd)
echo ${wkdir#$root} $(git -C $wkdir rev-parse HEAD) $(git -C $wkdir config --get remote.origin.url)
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment