-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforkSync
executable file
·41 lines (36 loc) · 1.16 KB
/
forkSync
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
#!/usr/bin/env bash
#
# Description:
# Script to sync your forks, incl branches and tags.
# // A modified version of: https://git.io/vh10n
#
# Usage:
# forkSync <upstream-remote> <target-remote>
# forkSync # upstream origin (default values)
# forkSync foo bar # foo bar
# forkSync foo # foo origin
# forkSync '' bar # upstream bar
#
# Help
[[ ${#} < 1 || ${1} == '-h' ]] && sed -n '6,13p' ${0} && exit 1;
# Vars
_upstream=${1:-'upstream'};
_origin=${2:-'origin'};
# Sync
echo ":: This will setup '${_origin}' to sync/track all branches in '${_upstream}'.";
read -p ":: Are you sure? (Y/n): " -n 1 -r;
if [[ ${REPLY} =~ ^[Yy]$ || ${REPLY} == '' ]]; then
echo && for _branch in `git branch -r | grep "${_upstream}" | egrep -v 'master|main' | grep -v HEAD | sed -e 's/.*\///g'`; do
git branch --track ${_branch} ${_upstream}/${_branch};
done
else
echo && exit;
fi
# Push
echo ":: This will push all local branches and tags into '${_origin}'";
read -p ":: Are you sure? (Y/n): " -n 1 -r;
if [[ ${REPLY} =~ ^[Yy]$ || ${REPLY} == '' ]]; then
echo && git push --all ${_origin} && git push --tags ${_origin};
else
echo && exit;
fi