Created
January 10, 2016 05:25
-
-
Save jpmckinney/487eda83843b42f88837 to your computer and use it in GitHub Desktop.
Makefile for reporting the status, unpushed commits, branches and stashes of all repositories in a directory. Useful if you have a lot of repositories.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run all these commands with the `-s` flag. | |
# Prints the status of all unclean repositories. | |
status: | |
for dir in */; do \ | |
if [ -d $$dir/.git ]; then \ | |
cd $$dir; \ | |
if [[ ! -z `git st` ]]; then \ | |
echo $$dir; \ | |
git st; \ | |
fi; \ | |
cd ..; \ | |
fi \ | |
done | |
# Checks whether any repositories have unpushed commits. | |
# | |
# If you get errors like "fatal: No upstream configured for branch '<branch>'", | |
# then you must `git push -u origin`. | |
ahead: | |
for dir in */; do \ | |
if [ -d $$dir/.git ]; then \ | |
cd $$dir; \ | |
if [[ ! -z `git remote` ]] && [[ ! -z `git rev-list @{u}..` ]]; then \ | |
echo $$dir; \ | |
git rev-list @{u}..; \ | |
fi; \ | |
cd ..; \ | |
fi \ | |
done | |
# Prints a repository's branch if it's not master. | |
branch: | |
for dir in */; do \ | |
if [ -d $$dir/.git ]; then \ | |
cd $$dir; \ | |
if [[ "refs/heads/master" != `git symbolic-ref HEAD` ]] && [[ "refs/heads/gh-pages" != `git symbolic-ref HEAD` ]]; then \ | |
echo $$dir; \ | |
git branch; \ | |
fi; \ | |
cd ..; \ | |
fi \ | |
done | |
# Prints a repository's stashes. | |
stash: | |
for dir in */; do \ | |
if [ -d $$dir/.git ]; then \ | |
cd $$dir; \ | |
if [[ ! -z `git stash list` ]]; then \ | |
echo $$dir; \ | |
git stash list; \ | |
fi; \ | |
cd ..; \ | |
fi \ | |
done | |
# Performs a commit on each repository. | |
commit: | |
for dir in */; do \ | |
if [ -d $$dir/.git ]; then \ | |
echo $$dir; \ | |
cd $$dir; \ | |
git ci -q ${ARGS}; \ | |
cd ..; \ | |
fi \ | |
done | |
# Pushes all repositories with unpushed commits. | |
push: | |
for dir in */; do \ | |
if [ -d $$dir/.git ]; then \ | |
cd $$dir; \ | |
if [[ ! -z `git remote` ]] && [[ ! -z `git rev-list @{u}..` ]]; then \ | |
echo $$dir; \ | |
git -q push; \ | |
fi; \ | |
cd ..; \ | |
fi \ | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment