Skip to content

Instantly share code, notes, and snippets.

@ArcTanSusan
Last active January 3, 2016 04:49
Show Gist options
  • Save ArcTanSusan/8411119 to your computer and use it in GitHub Desktop.
Save ArcTanSusan/8411119 to your computer and use it in GitHub Desktop.
Automate your git workflow with the IPython notebook
# Problem Statement:
# You have mulitple copies (or clones) of upstream repositories in your local drive.
# Your local cloned repos need to be updated against the upstream master repos on a regular basis.
# Here's one solution that uses the IPython notebook.
# Open up your IPython notebook browser in your working directory and then paste the following into a code cell.
# Press SHIFT+ENTER to run the code cell.
# Create a list of projects located in the working directory.
list_of_projects = ["django", "ipython", "oh-mainline"]
def update_and_push_to_origin(folder):
%cd {folder}
!git checkout master
!git fetch upstream
!git stash #Stash any un-committed changes before you rebase against upstream master.
!git rebase upstream/master
print "Updating your origin master branch on Github."
!git push origin master
# Iterate through each project in the array and update each project.
for project in list_of_projects:
print "\nCurrently updating the {!s} project.".format(project)
print "-------------------------------------------------------------\n"
update_and_push_to_origin(project)
%cd ..
# Reference: Adapted from IPython core developer Damian Avilla's blog post: http://www.damian.oquanta.info/posts/dont-write-scripts-just-write-ipyscripts.html
@ArcTanSusan
Copy link
Author

To run IPython scripts on the command terminal, install runipy: https://github.com/paulgb/runipy

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