Created
December 27, 2023 15:56
-
-
Save andremueller/3e88e28c8cc99a77173bdd00af6483bd to your computer and use it in GitHub Desktop.
Git set remote from `git remote -v` call
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
#!/usr/bin/bash | |
# allows to play back a remote configuration backed up with `git remote -v > remote.txt` | |
set -o errexit | |
set -o nounset | |
shopt -s nullglob | |
remoteFile="$1" | |
[[ -f "$remoteFile" ]] || { echo "Error: file $remoteFile does not exist"; exit 1; } | |
while read name url ; do | |
if git remote get-url "$name" >/dev/null 2>&1 ; then | |
echo "Remote $name already exists" | |
else | |
echo "Setting remote $name to $url" | |
git remote add "$name" "$url" | |
fi | |
done < <(cat "$remoteFile" | awk -c '{print $1, $2;}' | uniq) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment