Skip to content

Instantly share code, notes, and snippets.

@csarrazi
Last active August 29, 2015 14:20
Show Gist options
  • Save csarrazi/9316710d031ba306aa0a to your computer and use it in GitHub Desktop.
Save csarrazi/9316710d031ba306aa0a to your computer and use it in GitHub Desktop.
Useful commands for working with git repositories from the outside, or managing multiple git repositories in the same folder
#!/bin/bash
rgit () {
if [[ "$#" -lt 2 ]]; then
echo "usage: rgit <repository-path> <command> [<args>]"
return 1
fi
local worktree=$1
shift
git -C $worktree $@
}
multigit () {
if [[ "$#" -lt 2 ]]; then
echo "usage: multigit <repository-path> <command> [<args>]"
return 1
fi
local folder=$1
shift
cd "$folder"
find . -maxdepth 1 ! -path . -type d -print | while read -r i; do rgit "$i" $@; done;
cd -
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment