Skip to content

Instantly share code, notes, and snippets.

@abbottc
Created April 2, 2015 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save abbottc/fd2be585bf1788e0910f to your computer and use it in GitHub Desktop.
Save abbottc/fd2be585bf1788e0910f to your computer and use it in GitHub Desktop.
Linux shell script to automate the setup tasks for doing work on public Github Python projects
#!/bin/bash -i
# Note: Script must run in interactive mode (/bin/bash -i) in shebang line
# Description:
# Automatically fork an open source Github Python project and setup a local
# virtual environment to work on it inside a new branch.
# This is especially useful for quickly submitting a patch to a project, and
# is just a wrapper script tying together a few existing great utilities.
# Usage:
# $ github_fork <repo_username> <repo_name> <new_branch_name>
# Example:
# To fix a bug in, say, the mezzanine project:
# $ github_fork stephenmcd mezzanine mybugfix
# Now it's forked, and you're ready start working in the new local branch
# "mybugfix", which has been created in a virtual env.
# Requirements:
# - a Github account
# - git
# - hub (https://github.com/github/hub)
# - virtualenvwrapper (https://bitbucket.org/dhellmann/virtualenvwrapper/)
REPO_USERNAME=$1
REPO_NAME=$2
FEATURE_NAME=$3
# Enable virtualenvwrapper commands
source /usr/local/bin/virtualenvwrapper.sh
alias git=hub
cd $PROJECT_HOME
echo "----> Cloning $REPO_NAME"
git clone $REPO_USERNAME/$REPO_NAME
echo "----> Creating virtual environment"
mkvirtualenv $REPO_NAME
cd $REPO_NAME
setvirtualenvproject
echo "----> Creating new local branch $FEATURE_NAME"
git checkout -b $FEATURE_NAME
echo "----> Forking $REPO_NAME on GitHub"
git fork
echo
echo "======================================================================="
echo "When finishing and commiting the repo changes, type:"
echo "$ git push <your_github_username> $FEATURE_NAME"
echo "Then..."
echo "$ git pull-request"
echo "...a text editor will open to enter the pull request's title & message"
echo "======================================================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment