-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMergeProduction.sh
48 lines (39 loc) · 1.1 KB
/
MergeProduction.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
#!/bin/bash
# FROM: https://gist.github.com/tmiller/5222478
# Merges the master branch into all other branches
#
# Process:
#
# - Save the name of the current branch
# - If the current branch is not master then checkout master.
# - Pull the latest changes for master from its upstream branch.
# - Loop over each local branch.
# - If the branch is not master.
# - Checkout the branch.
# - Merge master into the branch.
# - If the current branch is not the saved branch name checkout the saved
# branch name
MAIN_BRANCH="Production"
# Returns the names of all the local branches
local_branches()
{
git for-each-ref --format="%(refname:short)" refs/heads
}
# Returns the name of the current branch
current_branch()
{
git symbolic-ref --short HEAD
}
saved_branch=$(current_branch)
[[ "${saved_branch}" != "${MAIN_BRANCH}" ]] && git checkout "${MAIN_BRANCH}"
git pull
for branch in $(local_branches); do
if [[ "${branch}" != "${MAIN_BRANCH}" ]]; then
echo
git checkout "${branch}"
git merge "${MAIN_BRANCH}"
git push
fi
done
echo
[[ "${saved_branch}" != "$(current_branch)" ]] && git checkout "${saved_branch}"