Want to fork your own gists? No fork button? No problem! Install this user script by clicking refork.user.js' "raw" link down below: ⇓
-
-
Save johan/1306266 to your computer and use it in GitHub Desktop.
// ==UserScript== | |
// @name (Re)fork any gist, including your own | |
// @namespace https://github.com/johan | |
// @version 2.0 - updated 2015-06-21 | |
// @description Adds a "fork" button to gists missing one at gist.github.com, so you can create multiple forks | |
// @match https://gist.github.com/* | |
// @include https://gist.github.com/* | |
// ==/UserScript== | |
if (/^\/[^\/]+\/\d+/.test(location.pathname) && | |
!document.querySelector('form[action$="/fork"]')) { | |
var actions = document.querySelector('.gisthead .pagehead-actions') | |
, auth = document.querySelector('input[name="authenticity_token"]').outerHTML | |
, fork = document.createElement('li') | |
, url = location.pathname + '/fork' | |
; | |
fork.innerHTML = '<form accept-charset="UTF-8" action="'+ url + '" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓">' + auth + '</div><button class="btn btn-sm" type="submit"><span class="octicon octicon-repo-forked"></span>Fork</button></form>'; | |
actions.appendChild(fork); | |
} |
@RichardBronosky I assume github does not recognize it as a fork and doesn't link the two gists together, right?
@RichardBronosky I assume github does not recognize it as a fork and doesn't link the two gists together, right?
@ackvf I updated my comment to include a link to a fork I just made of this gist. The gist.github.com web interface doesn't indicate the fork, but the complete history is there including accurate authors and dates. I have an old fork of this repo https://gist.github.com/RichardBronosky/4d8a7aed9f8dc40eea669a0985ac8d79 and it does indicate the fork. I'll compare the 2 and see if I can find anything in .git
folder that will serve as the fork indicator.
Thank you. I've already been cloning my gists using Sourcetree and actually I've been using local repo to manipulate / clean the gist history.
Anyway, forking own repo does not seem to be supported at all: "message": "You cannot fork your own gist."
@RichardBronosky did you ever figure out what specifically makes a fork be indicated in the gist web interface?
This no longer works because the fork link has been replaced with a form that includes a
authenticity_token
field. I don't think there is any way around that from the browser.I now use https://github.com/defunkt/gist from the CLI to:
credential-helper
)original_url="[email protected]:1306266.git"
url="$(date | gist -f temp)"
git clone $url; cd $(basename $url)
git remote add alt $original_url; git fetch alt
git reset --hard alt/main
git push -f origin main
Note
The
#
are in there so you can copy-pasta the whole block into the terminal 😉Update on 2022/04/14
main
because github changed their default branch causing my code above to error.