Skip to content

Instantly share code, notes, and snippets.

@sio sio/git-projects.sh
Created Sep 7, 2017

Embed
What would you like to do?
Manage multiple Git projects at once (check status, view logs...)
#!/bin/bash
set -e
#
# Execute the same git command in all project directories.
#
# Extra command line arguments are passed to git.
# If no arguments are specified, `git status` is assumed.
#
# File `projects.txt` has to contain paths to all project
# directories separated by a newline, and has to be located
# in the same directory as this script. Project paths are
# resolved relative to the script's location.
#
#
# Copyright 2017 Vitaly Potyarkin
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
PROJECT_ROOT=$(dirname "$0")
PROJECT_LIST="$PROJECT_ROOT/projects.txt"
_resolve_path() {
# Usage: _resolve_path RELATIVE [START]
#
# Resolve RELATIVE path to absolute; if START is given,
# resolve from there.
local START
[ -z "$2" ] && START="$PWD" || START="$2"
pushd "$START" > /dev/null || return $?
readlink -m "$1"
popd > /dev/null || return $?
}
if [ -z "$*" ]
then
ACTION="status"
else
ACTION="$*"
fi
sort -h "$PROJECT_LIST" | while read DIR
do
echo -e "\n$DIR"
DIR=$(_resolve_path "$DIR" "$PROJECT_ROOT")
git -C "$DIR" $ACTION
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.