Skip to content

Instantly share code, notes, and snippets.

@jasonm23
Last active August 30, 2022 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonm23/3ea1ae95814a1e0297ee889cf51e4d00 to your computer and use it in GitHub Desktop.
Save jasonm23/3ea1ae95814a1e0297ee889cf51e4d00 to your computer and use it in GitHub Desktop.

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