Skip to content

Instantly share code, notes, and snippets.

@myano
Last active August 25, 2021 11:56
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myano/5315439 to your computer and use it in GitHub Desktop.
Save myano/5315439 to your computer and use it in GitHub Desktop.
Merging forked gists into your gist to preserve the history of the gist.

Merging A Forked Gist Into Your Gist

Let's say you have a gist (public or private) and someone forks it and makes changes to it. Awesome! However, now you want to merge in their changes to your gist. Unfortunately, it doesn't seem GitHub supports this via their website at the moment, however, you can still merge the gists with 'git' on the command line.

  1. You want to clone your gist. You can locate the link for this under "Clone this gist"

     ➜  ~/dev » git clone https://gist.github.com/5315168.git
     Cloning into '5315168'...
     remote: Counting objects: 6, done.
     remote: Compressing objects: 100% (4/4), done.
     remote: Total 6 (delta 1), reused 0 (delta 0)
     Unpacking objects: 100% (6/6), done.
     ➜  ~/dev » cd 5315168
     ➜  ~/dev/5315168 ‹master› » ll
     total 16K
     -rw-r--r-- 1 yano yano 3.3K Apr  4 19:12 gistfile1.txt
     drwxr-xr-x 8 yano yano 4.0K Apr  4 19:12 .git
    
  2. Add the forked gist as a remote.

     ➜  ~/dev/5315168 ‹master› » git remote add fork1 https://gist.github.com/5315193.git
    
  3. Pull down the remote.

     ➜  ~/dev/5315168 ‹master› » git pull fork1 master
     remote: Counting objects: 5, done.
     remote: Compressing objects: 100% (2/2), done.
     remote: Total 3 (delta 1), reused 0 (delta 0)
     Unpacking objects: 100% (3/3), done.
     From https://gist.github.com/5315193
      * branch            master     -> FETCH_HEAD
     Updating a436dd9..e4fedc7
     Fast-forward
      gistfile1.txt |    2 ++
      1 file changed, 2 insertions(+)
    
  4. Push back up to your gist. You'll need to enter your credentials.

     ➜  ~/dev/5315168 ‹master› » git push
     Username for 'https://gist.github.com': myano
     Password for 'https://myano@gist.github.com': 
     Counting objects: 5, done.
     Delta compression using up to 4 threads.
     Compressing objects: 100% (2/2), done.
     Writing objects: 100% (3/3), 279 bytes, done.
     Total 3 (delta 1), reused 0 (delta 0)
     To https://gist.github.com/5315168.git
        a436dd9..e4fedc7  master -> master
    
  5. See the changes at your gist, https://gist.github.com/myano/5315168 You can see that the history is preserved.

After some quick testing it appears that gist does not understand or care about other branches besides master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment