aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2017-11-23 12:38:55 -0200
committerSilvio Rhatto <rhatto@riseup.net>2017-11-23 12:38:55 -0200
commitbf982162dd9b00c7506799ef97c3fc690139cd29 (patch)
tree0f5b19f35a84725cbd3861fb006df00a19d8d831
parent50fa88e6ee05f2077464769a9a33a0e7e9febb6e (diff)
downloadutils-git-bf982162dd9b00c7506799ef97c3fc690139cd29.tar.gz
utils-git-bf982162dd9b00c7506799ef97c3fc690139cd29.tar.bz2
Adds git-remote-all
-rwxr-xr-xgit-remote-all41
1 files changed, 41 insertions, 0 deletions
diff --git a/git-remote-all b/git-remote-all
new file mode 100755
index 0000000..496cc21
--- /dev/null
+++ b/git-remote-all
@@ -0,0 +1,41 @@
+#!/bin/bash
+#
+# Automate handling of the 'all' remote.
+#
+# See github - Git - Pushing code to two remotes - Stack Overflow -
+# https://stackoverflow.com/questions/14290113/git-pushing-code-to-two-remotes#14290145
+
+# Parameters
+BASENAME="`basename $0`"
+
+# Usage
+if [ -z "$1" ]; then
+ echo "usage: $BASENAME remote1 [remote2 ...]"
+fi
+
+# Process each remote
+for remote in $*; do
+ # Skip inexistent remotes
+ if ! git remote get-url $remote &> /dev/null; then
+ echo "Remote $remote does not exist, skipping..."
+ continue
+ fi
+
+ # Skip itself
+ if [ "$remote" == "all" ]; then
+ echo "Skipping remote 'all'..."
+ continue
+ fi
+
+ # Get remote push URL
+ url="`git remote get-url --push $remote`"
+
+ echo "Adding $url as a pushurl for remote 'all'..."
+
+ # Add current remote as a push URL for remote 'all'
+ if ! git remote get-url --push all &> /dev/null; then
+ git remote add all $url
+ else
+ git remote set-url --add --push all $url
+ fi
+done