6

How do I fork my own GitHub gist?

One possibility: there is a script posted on gist but I don't know how to install it on my gitHub. In that case, an explanation how to use the script and what it's doing.

(Re)Fork any gist, including your own

<!-- language: lang-js -->
// ==UserScript==
// @name           (Re)fork any gist, including your own
// @namespace      https://github.com/johan
// @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('a img[alt="fork"]')) {
  var i = document.createElement('img')
    , a = document.createElement('a')
    , u = document.querySelector('img.button').src
    , p = document.querySelector('.title');

  a.title = 'Create another fork of this gist';
  a.style.cssText = 'float: right; margin: 4px 7px 0';
  a.addEventListener('click', fork);
  a.appendChild(i);

  i.alt = 'fork';
  i.src = u.replace(/[^\/]*$/, 'fork_button.png');
  i.className = 'button';

  p.appendChild(a);
}

function fork(e) {
  var f = document.body.appendChild(document.createElement('form'));
  f.method = 'POST';
  f.action = '/fork' + location.pathname;
  f.appendChild(document.querySelector('input[name=authenticity_token]'));
  f.submit();
  return false;
}

StackOverflow shows how to fork your own GitHub repository.

Community
  • 1
  • 1
john mangual
  • 7,718
  • 13
  • 56
  • 95

2 Answers2

2

Try the Fork your own Gist bookmarklet.

It adds a fully functional Fork button to your own Gist.

If a Fork button is already present in the page, this bookmarklet will set focus to it instead of adding another one.

The change is temporary and the button will disappear as soon as you navigate away from that Gist (clicking the Fork button does this for you as well).

antichris
  • 2,827
  • 1
  • 22
  • 18
  • 3
    I forked this version of yours, made 2 fixes, and edited readme to explain to firefox users how to do it. [Located here - Gist Fork](https://gist.github.com/Noitidart/8794639). I also made a firefox addon out of it ([located here - ghForkable](https://addons.mozilla.org/en-US/firefox/addon/ghforkable/)) – Noitidart Feb 16 '14 at 22:59
  • I am now getting an error `Uncaught TypeError: $ is not a function` from the bookmarklet in the answer. – Bruno Bronosky Dec 14 '16 at 19:00
2

This seems to not be possible any more. Even when using the Github API you get this response:

https://api.github.com/gists/:gist_id/forks
{
  "message": "You cannot fork your own gist.",
  "errors": [
    {
      "resource": "Gist",
      "field": "forks",
      "code": "unprocessable"
    }
  ],
  "documentation_url": "https://docs.github.com/v3/gists/#fork-a-gist"
}

https://docs.github.com/v3/gists/#fork-a-gist


You can upvote this suggestion, let's see if we get somewhere.
https://github.com/github/feedback/discussions/14882

Qwerty
  • 29,062
  • 22
  • 108
  • 136