Skip to content

Instantly share code, notes, and snippets.

@CraZySacX
Created February 19, 2014 14:24
Show Gist options
  • Save CraZySacX/9093122 to your computer and use it in GitHub Desktop.
Save CraZySacX/9093122 to your computer and use it in GitHub Desktop.
Python script that aids with merging upstream projects with origin. Useful for github forks.
#!/usr/bin/python3
import argparse
import os
from os import environ
from subprocess import check_call
# Store the current directory
owd = os.getcwd()
# Setup the supported command-line arguments
parser = argparse.ArgumentParser(description='Useful for merging upstream branches')
parser.add_argument('-d', '--dir', default=str(environ['HOME'] + "/projects"))
parser.add_argument('-p', '--project', required=True)
parser.add_argument('-b', '--branch', nargs='+')
parser.add_argument('-u', '--upstream', default='upstream')
# Parse the command-line arguments
args = parser.parse_args()
# Change working directory
os.chdir(str(args.dir + "/" + args.project))
# Checkout and merge each branch
for b in args.branch:
check_call(["git", "checkout", str(b)])
check_call(["git", "merge", args.upstream + "/" + str(b)])
# Push all the merges
check_call(["git", "push", "--all"])
# Change back to the original directory
os.chdir(owd)
@CraZySacX
Copy link
Author

Usage merger.py -p v8 -b bleeding_edge master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment