-
-
Save waqashamid/41d50c9f95833cf5884dd3f9fa3d3970 to your computer and use it in GitHub Desktop.
Bash script to merge master into all branches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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