Skip to content

Instantly share code, notes, and snippets.

@waqashamid
Forked from tmiller/merge
Created May 17, 2018 06:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save waqashamid/41d50c9f95833cf5884dd3f9fa3d3970 to your computer and use it in GitHub Desktop.
Bash script to merge master into all branches
#!/bin/bash
# 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
# 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}" != "master" ]] && git checkout "master"
git pull
for branch in $(local_branches); do
if [[ "${branch}" != "master" ]]; then
echo
git checkout "${branch}"
git merge "master"
fi
done
echo
[[ "${saved_branch}" != "$(current_branch)" ]] && git checkout "${saved_branch}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment