Skip to content

Instantly share code, notes, and snippets.

@kenmueller
Created June 19, 2019 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenmueller/7b46fa8bcd63f145d7bc3e2ae0d25941 to your computer and use it in GitHub Desktop.
Save kenmueller/7b46fa8bcd63f145d7bc3e2ae0d25941 to your computer and use it in GitHub Desktop.
Bash script for backing up git repositories
# Before copying, replace GITHUB_USERNAME shown below with your GitHub username
# Copy this into your .bash_profile found in ~/
# When you're inside of a git repo, call "backup" without any arguments to back up the current git repo
# Even when you are outside of a git repo, call "backup REPO_NAME", for example "backup typescript"
function backup() {
if [ -z "$1" ]
then
cloneUrl=$(git config --get remote.origin.url)
else
cloneUrl="https://github.com/GITHUB_USERNAME/$1.git"
fi
oldDir="$PWD"
cd ~/Files/Backups
base=${cloneUrl##*/}
rm -rf ${base%.*}
git clone "$cloneUrl"
cd "$oldDir"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment