-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-initremote
More file actions
executable file
·34 lines (27 loc) · 1 KB
/
git-initremote
File metadata and controls
executable file
·34 lines (27 loc) · 1 KB
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
#!/bin/zsh
# git-initremote - initialize a remote git repository
#
# Copyright 2013 by David Lindes. All Rights Reserved.
#
# See accompanying LICENSE file for licensing information.
# for some reason, if we just use 'ssh', git says the command isn't
# found... and yet, it can find it this way:
ssh=`which ssh`
# If we haven't specified any remotes on the command-line, default to 'origin':
if [ -z "$*" ]
then
set -- origin
fi
# Loop through remotes, attempting to create remote directories as
# empty bare repos, ready to push to:
for remote in "$@"
do
# first, get the URL from 'git remote':
# (Note: that's a hard tab in the grep string.)
read name url extra < <(git remote -v | grep "^$remote " | grep push)
# next parse URL into host and path:
IFS=":" read host path < <(echo "$url")
# Finally, ssh to $host to create it, unless it already exists (in
# which case do nothing):
$ssh "$host" "test ! -d $path && git init --bare $path || echo '$host:$path: Already exists'"
done