Last active
January 10, 2021 05:29
-
-
Save riemannulus/f7287a90720fcef76d188056d53bb5d4 to your computer and use it in GitHub Desktop.
Add upstream
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
function add_upstream() { | |
url=$(git config --get remote.origin.url) | |
repo=${url##*/} | |
if [[ "$repo" =~ ".git" ]]; then | |
repo=$(echo "$repo" | awk -F. '{print $1}') | |
fi | |
user=$(echo "$url" | awk -F/ '{print $4}') | |
if [ -z "$user" ]; then | |
user=$(echo "$url" | awk -F: '{print $2}' | awk -F/ '{print $1}') | |
fi | |
remote=$(curl -s "https://api.github.com/repos/$user/$repo" | jq -r '.parent.clone_url') | |
if [ "$remote" != "null" ]; then | |
git remote add upstream "$remote" | |
else | |
echo "no upstream found" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment