#!/bin/bash declare -A usage declare -A varia summary="$0 [options] " usage[b]="Branch of git repo" varia[b]=branch branch=master usage[d]="Destination of clone" varia[d]=dst dst='.' usage[i]="privkey used to ssh pull" varia[i]=privkey privkey='' . driglibash-args # Some SSH options ssh_opt='ssh' if [ -n "$privkey" ] ; then ssh_opt="$ssh_opt -i $privkey" fi repo="$1" if [ -z "$repo" ] ; then die "$0: Empty repo given\n$summary" fi cd "$dst" if [ -d .git ] ; then git fetch origin "$branch" git checkout --force -B "$branch" "origin/$branch" git reset --hard git clean -qffdx git submodule update --init --recursive --force --recommend-shallow git submodule foreach git fetch git submodule foreach git checkout --force -B "$branch" "origin/$branch" git submodule foreach git reset --hard git submodule foreach git clean -fdx else git clone -b "$branch" --single-branch --recurse-submodules --shallow-submodules --depth 1 --config core.sshCommand="$ssh_opt" "$repo" . fi