-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_pull
64 lines (50 loc) · 1.01 KB
/
git_pull
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
#! /usr/bin/env bash
working_dir = "<working dir> "
list=$(cd ~/"$working_dir"; ls)
for t in $list; do
cd ~/"${working_dir}/$t"
is_git="$(git rev-parse --is-inside-work-tree)"
echo "On $t"
if [ "$is_git" ]
then
my_branch=$(git symbolic-ref --short -q HEAD)
branch="master"
exception_branch = "<exception_branch"
if [ "$t" = "$exception_branch" ]
then
branch="<other_name>"
fi
cd ~/"${working_dir}/$t"
git checkout $branch
if [ $? -ne 0 ]
then
git stash
git checkout $branch
git pull
git checkout $my_branch
git stash apply
else
git pull
fi
ret_code=$?
choice="N"
if [ $ret_code -ne 0 ]
then
read -p "There are unstashed changes. Do you want to stash and pull (Y/N) ?" choice
if [ $choice == "Y" ]
then
git stash
git pull
else
echo "Unstaged changes. Unable to pull from $t $branch"
fi
fi
if [ "$my_branch" != "$branch" ]
then
git checkout $my_branch
fi
else
echo "Skipping $t, not a git repository."
fi
echo
done