Skip to content

Instantly share code, notes, and snippets.

@chernjie
Last active August 29, 2015 14:22
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 chernjie/603cb2ea286ebce8fee0 to your computer and use it in GitHub Desktop.
Save chernjie/603cb2ea286ebce8fee0 to your computer and use it in GitHub Desktop.

git-gh-setup


This scripts will find all github remotes in the current repository and add a new configuration that allows you to fetch pull request heads and merge-heads

+refs/pull/*/head
+refs/pull/*/merge

Example:

$ cd git-repo
$ git gh-setup
adding refs/pull/* to origin

# Now, attempt a fetch from github
$ git fetch
From git@github.com:chernjie/git-gh-setup
 * [new ref]         refs/pull/1/head -> origin/pull/1/head
 * [new ref]         refs/pull/1/merge -> origin/pull/1/merge
 * [new ref]         refs/pull/2/head -> origin/pull/2/head
 * [new ref]         refs/pull/2/merge -> origin/pull/2/merge

# Take a look at your logs
$ git log --oneline --decorate --graph --all
#!/usr/bin/env bash
git config --get-regexp remote.*url github |
cut -d. -f2 |
while read remote
do
if ! git config --get-regexp remote.$remote.fetch refs/pull > /dev/null
then
echo adding refs/pull/* to $remote >&2
git config --add remote.$remote.fetch +refs/pull/*:refs/remotes/$remote/pull/*
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment