Skip to content

Instantly share code, notes, and snippets.

@david-bakin-sl
Created March 11, 2024 17:14
Show Gist options
  • Save david-bakin-sl/5a05875206bef43e0cffa6a3dfe64dd7 to your computer and use it in GitHub Desktop.
Save david-bakin-sl/5a05875206bef43e0cffa6a3dfe64dd7 to your computer and use it in GitHub Desktop.
Show current branch of all repos under current directory
#!/usr/bin/env bash
# Show current branch for all repos under current directory (avoids submodules)
for repo in $(find . -type d -execdir test -d {}/.git \; -prune -print | sed 's/^\.\///g' | sort);
do
cd $repo
branch=$(git branch --show-current)
echo "$repo = $branch"
cd $OLDPWD
done
@jsync-swirlds
Copy link

Suggested minor improvement:

do
  pushd $repo >>/dev/null
  branch=$(git branch --show-current)
  echo "$repo = $branch"
  popd >>/dev/null
done

@ElijahLynn
Copy link

cd - changes to the previous directory.

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