Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert files in GitHub repository to a Gist

Tags:

git

github

gist

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?

like image 967
bill_e Avatar asked Oct 05 '15 17:10

bill_e


People also ask

How do I create a gist link in GitHub?

If you go back to your Github homepage, to the right of the create button is your picture. That dropdown menu is going to give you links to your profile and settings — but more importantly your repos, projects, and gists. Click on the link for Your gists.

How do I edit my gist on GitHub?

How Do I Edit or Delete a Gist? In the top right corner of your gist page, there will be a menu that allows for multiple functions to be performed on your gist. We can edit, delete, unsubscribe, star, embed, copy, share, and download a raw copy or zipped copy of a gist. We also can share a gist in multiple ways.


1 Answers

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 [email protected]:792bxxxxxxxxxxxxxxx9.git 
  2. cd to that gist directory

  3. Pull and merge from your GitHub repository:

    git pull [email protected]:<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 [email protected]:<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 [email protected]:792.....0b79.git  ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to '[email protected]:79.......9.git' 
like image 51
Ionică Bizău Avatar answered Sep 26 '22 22:09

Ionică Bizău