33

What I would like to do is the inverse of this question. I have a folder within a GitHub repo that contains a d3 visualization that I would like to continue making changes to. It would be nice to have a "gist" version of this repo to display the visualization on bl.ocks.org that I could push changes to when from the primary repo after I am happy with them.

Another similar question is here, but the answers describe the step gist -> bl.ocks.org. I am unsure of the step githup repo -> gist. What is the best way to accomplish this?

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
bill_e
  • 930
  • 2
  • 12
  • 24

1 Answers1

30

First of all, note that Gist doesn't support directories. To import a repository into a gist follow the next steps:

  1. Create a new gist and clone it locally (replace the dummy id with your Gist id):

    git clone git@gist.github.com:792bxxxxxxxxxxxxxxx9.git
    
  2. cd to that gist directory

  3. Pull and merge from your GitHub repository:

    git pull git@github.com:<user>/<repo>.git
    
  4. Push your changes

    git push
    

Again, note that if you have directories, you have to delete and commit them:

rm -rf some-directory
git commit -m 'Removed some-directory' .

Using the steps above, the project history will be kept. If you don't care about history, you can always push files in your Gist. Let's say you have a repository containing multiple folders and you want for each folder to create a Gist. You will repeat the next steps (or a script could do that):

git clone git@gist.github.com:<gist-id>.git
cd <gist-id>
cp ../path/to/your/github/repository/and/some/folder/* .
git add .
git commit -m 'Added the Gist files' .
git push

Gist is different than how GitHub works:

Gist is a simple way to share snippets and pastes with others. All gists are Git repositories, so they are automatically versioned, forkable and usable from Git.

However, if you try to push directories in Gists you will get errors from remote:

$ git push
Counting objects: 32, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (21/21), done.
Writing objects: 100% (32/32), 7.35 KiB | 0 bytes/s, done.
Total 32 (delta 10), reused 0 (delta 0)
remote: Gist does not support directories.
remote: These are the directories that are causing problems:
remote: foo
To git@gist.github.com:792.....0b79.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@gist.github.com:79.......9.git'
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • Thank you, but what do you mean Gist doesn't support directories? So what I have is a repo, with several folders. Within each folder is a standalone d3 visualization -- each folder contains index.html, style.css etc. Can I import the contents within each folder this way into separate Gists? – bill_e Oct 05 '15 at 17:45
  • @Andre5 You will have to create different gists for each one. If you want to automate the process, you may want to use the [Gists API](https://developer.github.com/v3/gists/). – Ionică Bizău Oct 05 '15 at 17:56
  • Yes, that is exactly what I want to do, create different gists for each one. Will your instructions apply in this case? – bill_e Oct 05 '15 at 17:57
  • @Andre5 In that case you want to just copy (`cp` ) the things in your Gist and commit them. See the edit. – Ionică Bizău Oct 05 '15 at 18:02
  • ahh thanks for the clarification, I'll give it a try now. – bill_e Oct 05 '15 at 18:05