Skip to content

Instantly share code, notes, and snippets.

@gadenbuie
Created February 26, 2019 15:13
Show Gist options
  • Save gadenbuie/1ab564c0a8be68fc6a0f837e41b42b6f to your computer and use it in GitHub Desktop.
Save gadenbuie/1ab564c0a8be68fc6a0f837e41b42b6f to your computer and use it in GitHub Desktop.
git outta here
#!/bin/bash
is_inside_git_repo() {
[ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1
}
has_origin_remote() {
git remote get-url origin > /dev/null 2>&1
}
git_outta_here() {
# Archive your current local git repository
# and re-clone from your current origin remote
if ! is_inside_git_repo; then
echo "Current directory is not inside a git repo"
return 1
fi
if [[ -z "$(git remote)" ]]; then
echo "Current repo has no remote branches"
return 1
fi
# Make sure we're at top level of repo
cd "$(git rev-parse --show-toplevel)" || exit
local reponame="${PWD##*/}"
if ! has_origin_remote; then
echo "Current repo doesn't have an origin remote"
return 1
fi
local repoorigin=$(git remote get-url origin)
cd ..
echo "Backing up ${reponame} to ${reponame}.old"
mv "$reponame" "${reponame}.old"
echo "Cloning origin repo from ${repoorigin}"
git clone "$repoorigin" "$reponame"
cd "$reponame" || exit
echo
echo "Fresh repository cloned into $(pwd)"
echo "Try not to mess this one up ;)"
}
@DaaniyaalM
Copy link

Hahaha I typed in git outta here into google and your repo popped up LOL nice puns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment