#/bin/bash if [ $# -ne 2 ]; then echo 1>&2 "Usage: $0 source_directory target_directory" exit 3 fi if [[ ! -d $1 ]]; then echo "ERROR: source $1 is not a directory" exit 1 fi if [[ -d $2 || -f $2 ]]; then echo "ERROR: target $2 exists already exist. Remove it and try again" exit 1 fi cp -r "$1" "$2" rm -rf "$2/.git" git -C "$1" ls-tree -r HEAD --name-only > "$2/gitfiles.txt" git -C "$2" init cat "$2/gitfiles.txt" | xargs git -C "$2" add git -C "$2" commit -m "initial commit"