Skip to content

Instantly share code, notes, and snippets.

@kepocnhh
Created July 14, 2026 14:20
Show Gist options
  • Select an option

  • Save kepocnhh/465ad76e7b6fd44e12d280c4c4126e96 to your computer and use it in GitHub Desktop.

Select an option

Save kepocnhh/465ad76e7b6fd44e12d280c4c4126e96 to your computer and use it in GitHub Desktop.
git_backups.sh
#!/usr/local/bin/bash
if [[ $# -ne 3 ]]; then
echo 'Wrong arguments!' >&2; exit 1; fi
CURRENT_DIR="$1"
if [[ -z "${CURRENT_DIR}" ]]; then
echo 'No path!' >&2; exit 1
elif [[ -L "${CURRENT_DIR}" ]]; then
echo "\"${CURRENT_DIR}\" is a symlink!" >&2; exit 1
elif [[ ! -e "${CURRENT_DIR}" ]]; then
echo "\"${CURRENT_DIR}\" does not exist!" >&2; exit 1
elif [[ ! -d "${CURRENT_DIR}" ]]; then
echo "\"${CHECKS_PATH}\" is not a dir!" >&2; exit 1
fi
REP_OWNER="$2"
if [[ -z "${REP_OWNER}" ]]; then
echo 'No rep owner!' >&2; exit 1; fi
REP_NAME="$3"
if [[ -z "${REP_NAME}" ]]; then
echo 'No rep name!' >&2; exit 1; fi
REP_OWNER_DIR="${CURRENT_DIR}/${REP_OWNER}"
if [[ ! -d "${REP_OWNER_DIR}/${REP_NAME}.git" ]]; then
echo "Git clone ${REP_OWNER}/${REP_NAME}..."
git clone --quiet --bare "https://github.com/${REP_OWNER}/${REP_NAME}.git" "${REP_OWNER_DIR}/${REP_NAME}.git"
if [[ $? != 0 ]]; then
echo "Git clone ${REP_OWNER}/${REP_NAME} error!" >&2; exit 1; fi
fi
echo "Git fetch ${REP_OWNER}/${REP_NAME}..."
git -C "${REP_OWNER_DIR}/${REP_NAME}.git" fetch --quiet -p --tags
if [[ $? != 0 ]]; then
echo "Git fetch ${REP_OWNER}/${REP_NAME} error!" >&2; exit 1; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment