Skip to content

Instantly share code, notes, and snippets.

@jasonm23
Last active Aug 30, 2022
Embed
What would you like to do?

ogit --- other git

On Unix-es use a function to wrap git

Usage: ogit "path/to/repo/" [git options & sub commands]

ogit() {
  _PATH=$1
  shift
  GIT_WORK_TREE="${_PATH%/.git}" GIT_DIR="${_PATH%/.git}"/.git git "$@"
}

Example...

ogit path/to/repo status --short

ogit-group (requires ogit)

Usage: ogit-group paths... -- [git options and sub commands]

ogit-group() {
  OGIT_PATHS_COMPLETED=0
  OGIT_PATHS=()
  for opt in "$@"; do
    [[ "--" == "$opt" ]] && OGIT_PATHS_COMPLETED=1 && shift
    [[ $OGIT_PATHS_COMPLETED == 1 ]] && break || OGIT_PATHS+=("$opt") && shift
  done
  for p in "$OGIT_PATHS[@]"; do
    echo "${p} --- git $@"
    ogit "$p" "$@"
  done
}

Example

ogit-group path/to/repo another/repo yet-another/repo -- status --short

or with globbing

ogit-group glob/path/repos* -- status --short
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment