Skip to content

Instantly share code, notes, and snippets.

@andremueller
Created December 27, 2023 15:56
Show Gist options
  • Save andremueller/3e88e28c8cc99a77173bdd00af6483bd to your computer and use it in GitHub Desktop.
Save andremueller/3e88e28c8cc99a77173bdd00af6483bd to your computer and use it in GitHub Desktop.
Git set remote from `git remote -v` call
#!/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