Skip to content

Instantly share code, notes, and snippets.

@maesitos
Last active September 8, 2022 20:29
Show Gist options
  • Save maesitos/2b487af512e2c17607d53066bccfcd2b to your computer and use it in GitHub Desktop.
Save maesitos/2b487af512e2c17607d53066bccfcd2b to your computer and use it in GitHub Desktop.
Back-up routine for backing up git into synology
# !/bin/bash
# Put here all the repos you want to back up
declare -a repositories=("repo_name")
# Path to repos
repo_path=/volume1/git/
for repo in "${repositories[@]}"; do
echo "** Pulling the entire repository '${repo}' **"
cd $repo_path$repo && \
git fetch --all --force --prune --tags && \
for i in `git branch -a | grep remote | grep -v HEAD`; do
if git branch --format='%(refname:short)' | grep -E "(^| )${i#remotes/origin/}( |$)"; then
echo "Branch '${i#remotes/origin/}' already tracked";
else
git branch --track ${i#remotes/origin/} $i;
#git checkout ${i#remotes/origin/}
fi
done;
for remote in `git branch -r | grep -v HEAD`; do
echo "Resetting and pulling '${remote#origin/}' Branch";
git reset --hard ${remote#origin/}; \
git pull origin ${remote#origin/} --ff-only;
done;
echo "** Done pulling the entire repository '${repo}' **"
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment