-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgit-local-branches
More file actions
executable file
·52 lines (43 loc) · 890 Bytes
/
git-local-branches
File metadata and controls
executable file
·52 lines (43 loc) · 890 Bytes
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
#!/bin/sh
usage()
{
cat >&2 << __EOF__
Usage: $(basename $0) repo
Options:
repo -- Location of the target git repository.
__EOF__
exit ${1-1}
}
log()
{
echo "$(basename $0): $1" >&2
}
while [ $# -gt 0 ]; do
case $1 in
-h)
usage 0
;;
*)
break
;;
esac
shift
done
[ $# -eq 1 ] || usage
repodir="$1"
[ -d "$repodir" ] || usage
cd "$repodir"
if ! git status >/dev/null 2>&1; then
log "'$repodir' isn't a git repository"
exit 1
fi
for branch in $(git branch --remotes | grep -v HEAD); do
localname=${branch##*/}
if [ -z "$(git branch --list $localname)" ]; then
errmsg=$(git branch --track "$localname" "$branch" 2>&1 >/dev/null)
[ $? -ne 0 ] && log "failed to create '$localname': $errmsg"
else
log "local branch '$localname' already exists; skipping"
fi
done
exit 0