Skip to content

Instantly share code, notes, and snippets.

@stefanv
Created October 11, 2014 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanv/e9135cc899deda1141b0 to your computer and use it in GitHub Desktop.
Save stefanv/e9135cc899deda1141b0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""git-nr: add new remote
git nr username
Adds remote "username" as git@github.com:username/current_repo.git
"""
import subprocess
import sys
if len(sys.argv) != 2:
print "Usage: git-nr github-username"
sys.exit(-1)
username = sys.argv[1]
out = subprocess.check_output("git remote show -n origin".split())
out = [l for l in out.split('\n') if "Fetch URL" in l][0]
url = out.strip().split(' ')[-1]
repo = url.split('/')[-1]
remote = "git@github.com:%s/%s" % (username, repo)
print "Adding remote %s" % remote
subprocess.check_output(('git remote add %s %s' % (username, remote)).split())
#!/usr/bin/env python
"""git-pr: fetch a pull request
git pr NR
git pr NR0 NR1 NR2
git pr NR0 NR1 NR2 -args -to -git-fetch
Adds a new branch "pr/NR"
"""
import subprocess
import sys
if len(sys.argv) < 2:
print "Usage: git-pr NR"
print "Usage: git-pr NR0 NR1 NR2 NR3"
print "Usage: git-pr NR0 NR1 NR2 -args -to -git-fetch"
sys.exit(-1)
opts = [arg for arg in sys.argv[1:] if arg.startswith('-')]
nrs = [int(arg) for arg in sys.argv[1:] if not arg.startswith('-')]
for i, nr in enumerate(nrs):
print "Fetching PR #{0} into branch 'pr/{0}'".format(nr)
cmd = "git fetch origin pull/{0}/head:pr/{0}".format(nr)
out = subprocess.check_output(cmd.split() + opts)
if i != len(nrs) - 1 and not out.endswith('\n'):
print
#!/bin/bash
set -o errexit
# Author: David Underhill
# Script to permanently delete files/folders from your git repository. To use
# it, cd to your repository's root and then run the script with a list of paths
# you want to delete, e.g., git-delete-history path1 path2
if [ $# -eq 0 ]; then
exit 0
fi
# make sure we're at the root of git repo
if [ ! -d .git ]; then
echo "Error: must run this script from the root of a git repository"
exit 1
fi
# remove all paths passed as arguments from the history of the repo
files=$@
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch $files" --prune-empty HEAD
# remove the temporary history git-filter-branch otherwise leaves behind for a long time
rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment