aboutsummaryrefslogtreecommitdiff
path: root/git-remote-all
blob: e6bd4bdb7f47bf688f7f53df14ba6c72aced63b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/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'..."

  # Ensure remote exists
  if ! git remote get-url --push all &> /dev/null; then
    git remote add all $url
  fi

  # Add current remote as a push URL for remote 'all'
  git remote set-url --add --push all $url
done