3 #==============================================================================
5 # File ID: b8c0ee54-eb71-11df-a07a-fefdb24f8e10
7 # Create or update local Git branches that exist in remote repositories.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
25 while test -n "$1"; do
27 -a|
--all) opt_all
=1; shift ;;
28 -C|
--create) opt_create
=1; shift ;;
29 -c|
--commit-branches) opt_commit_branches
=1; shift ;;
30 -f|
--force) opt_force
=1; shift ;;
31 -h|
--help) opt_help
=1; shift ;;
32 -n|
--dry-run) opt_dry_run
=1; shift ;;
33 -q|
--quiet) opt_quiet
=$
(($opt_quiet + 1)); shift ;;
34 -u|
--upstream) opt_upstream
=1; shift ;;
35 -v|
--verbose) opt_verbose
=$
(($opt_verbose + 1)); shift ;;
36 --version) echo $progname $VERSION; exit 0 ;;
39 if printf '%s\n' "$1" |
grep -q ^
-; then
40 echo "$progname: $1: Unknown option" >&2
48 opt_verbose
=$
(($opt_verbose - $opt_quiet))
50 if test "$opt_help" = "1"; then
51 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
54 Create or update local Git branches that exist in remote repositories.
56 Usage: $progname [options] [remote [remotes [...]]]
61 Create branches from all remotes. If this option is not specified,
62 only "origin" or remotes specified on the command line are scanned.
63 This option has no effect if any remotes are specified on the
66 Create new branches locally. Without this option, only already
67 existing branches will be updated.
69 Also create commit-* branches created by git-dangling.
71 Allow rewriting of local branches if fast-forward is not possible.
75 Don't make any changes, print the commands that would be executed.
77 Be more quiet. Can be repeated to increase silence.
78 One -q turns off the constantly updating branch name display.
80 Set local branches to track remote branches as upstream, similar
81 functionality to "git branch -u" and "git push -u". When used with
82 -a/--all, use the last remote in alphabetical order. If several
83 remotes are specified, the last one is used.
85 Increase level of verbosity. Can be repeated.
87 Print version information.
93 test "$opt_dry_run" = "1" && sim
="echo $progname: cmd: " || sim
=
95 test "$opt_all" = "1" && remotes
=$
(git remote
)
97 test "$opt_commit_branches" = "1" && create_dangling
=1
99 test "$opt_force" = "1" && force_str
="--force"
101 test "$opt_upstream" = "1" && upstream_str
="-u"
102 test -z "$1" || remotes
="$@"
105 test "$(git config --get core.bare)" = "true" || is_bare
=0
108 for remote
in $remotes; do
109 echo ==== $progname: remote
$remote
112 grep remotes
/$remote/ |
113 grep -v -E "remotes/$remote/HEAD( |\$)" |
114 perl
-pe "s!remotes/$remote/(.*)\$!\$1!" |
115 if test "$opt_commit_branches" = "1"; then
118 grep -v -E 'commit-[0-9a-f]{40}';
122 git for-each-ref
--format='%(refname:short)' \
123 refs
/heads
/ |
grep -q ^
$f\$
&& echo 1 ||
echo 0
125 if test $opt_verbose -ge 0; then
126 printf '%s%s\r' "$f" "$t_el"
128 test "$opt_create" = "0" -a "$branch_exists" = "0" && continue
130 if test "$branch_exists" = "1"; then
131 $sim git log
--format=%h refs
/heads
/$f..
$remote/$f |
132 grep -q .
&& $sim git push .
$remote/$f:refs
/heads
/$f \
134 grep -v '^Everything up-to-date'
136 $sim git branch
--no-track $f $remote/$f 2>&1 &&
137 echo $progname: Created
$f
139 ) |
grep -v '^fatal: A branch named .* already exists.'
140 test -n "$upstream_str" && $sim git branch
-u $remote/$f $f
146 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :