-
Notifications
You must be signed in to change notification settings - Fork 3
/
git-remote-add-all.sh
executable file
·92 lines (64 loc) · 2.17 KB
/
git-remote-add-all.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
main_branches="master journal"
username=milahu
force=true
function git_remote_add() {
local name="$1"
local url="$2"
exists=false
if git remote get-url "$name" >/dev/null 2>&1; then
exists=true
fi
if ! $force && $exists; then
# remote with this name already exists
echo "remote exists: $name"
return
fi
# add username
url="$(echo "$url" | sed -E "s|^(https?://)|\1${username}@|")"
if ! $exists; then
echo "adding remote: $name"
git remote add "$name" "$url"
else
echo "updating remote: $name"
git remote set-url "$name" "$url"
fi
if echo "$name" | grep -q '.onion$'; then
echo "torifying remote: $name"
git config --add "remote.$name.proxy" socks5h://127.0.0.1:9050
fi
}
git_remote_add github.com https://github.com/milahu/alchi
git_remote_add gitlab.com https://gitlab.com/milahu/alchi
git_remote_add codeberg.org https://codeberg.org/milahu/alchi
git_remote_add sourceforge.net https://git.code.sourceforge.net/p/milahu-alchi/code
git_remote_add notabug.org https://notabug.org/milahu/alchi
git_remote_add disroot.org https://git.disroot.org/milahu/alchi
git_remote_add sr.ht [email protected]:~milahu/alchi
git_remote_add darktea.onion http://it7otdanqu7ktntxzm427cba6i53w6wlanlh23v5i3siqmos47pzhvyd.onion/milahu/alchi
git_remote_add righttoprivacy.onion http://gg6zxtreajiijztyy5g6bt5o6l3qu32nrg7eulyemlhxwwl6enk6ghad.onion/milahu/alchi
# done
exit 0
# not needed?
# what problem should this solve?
if false; then
# fix error: There are multiple remotes whose fetch refspecs map to the remote
# caused by: git branch --set-upstream-to=...
if origin_url=$(git remote get-url origin); then
new_origin_name=""
git remote show | grep -v -x origin | while read remote; do
remote_url=$(git remote get-url $remote)
if [[ "$origin_url" == "$remote_url" ]]; then
new_origin_name="$remote"
break
fi
done
if [[ -n "$new_origin_name" ]]; then
git remote remove origin
# use the previous "origin" as default remote, so we can just "git pull" and "git push"
for branch in $main_branches; do
git branch --set-upstream-to=$new_origin_name/$branch $branch
fi
fi
fi
fi