Skip to content

Instantly share code, notes, and snippets.

@ryllada
Created October 11, 2016 11:35
Show Gist options
  • Save ryllada/19153bdef0d9c635c1e8b90222b05baa to your computer and use it in GitHub Desktop.
Save ryllada/19153bdef0d9c635c1e8b90222b05baa to your computer and use it in GitHub Desktop.
# -*- encoding: utf-8 -*-
import subprocess
import os
__author__ = 'Rodolfo Yllada (ryllada@gmail.com)'
# This little routine aims to transmit the changes commited in the master
# branch, to the rest of branches, that not are included in
# BRANCHES_TO_EXCLUDE list.
# This is very usefull when the approach is to use each additional branch for
# implement a new feature and there's a lot of branches. In this case, when a
# new feature is finished and it's merged into master branch, it's needed to
# merge these changes into remaining branches. It can be easily done by
# running this simple command.
BRANCHES_TO_EXCLUDE = ("master", "production", )
def run_bash_command(command):
return subprocess.Popen(
command.replace("git", "/usr/bin/git"), cwd=os.path.dirname('.'),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def define_command_string():
output, error = run_bash_command("git branch").communicate()
output = output.split(" ")
git_branches_list = [
x.replace("\n", "").replace("*", "") for x in output if x != ""]
if "*" in git_branches_list:
git_branches_list.remove("*")
for branch in git_branches_list:
if branch in BRANCHES_TO_EXCLUDE:
git_branches_list.remove(branch)
command_string = ""
for branch in git_branches_list:
if command_string:
command_string += " && "
command_string += "git checkout %s && git merge master" % branch
command_string += " && git checkout master"
return command_string
if __name__ == '__main__':
run_bash_command(define_command_string())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment