Created
June 19, 2019 03:12
-
-
Save kenmueller/7b46fa8bcd63f145d7bc3e2ae0d25941 to your computer and use it in GitHub Desktop.
Bash script for backing up git repositories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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