#!/bin/bash # # Update a subtree. # # Parameters BASENAME="`basename $0`" REMOTE="$1" FOLDER="$2" # Syntax if [ -z "$2" ]; then echo "usage: $BASENAME " exit 1 fi # Check remote if ! git remote | grep -qe "^$REMOTE"; then echo "fatal: no such remote $REMOTE" exit fi # Fetch the remote git fetch $REMOTE master # Process if [ ! -d "$FOLDER" ]; then # Add a subtree git subtree add --prefix $FOLDER $REMOTE master --squash else # Update a subtree git subtree pull --prefix $FOLDER $REMOTE master --squash fi