Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active November 21, 2023 05:48
Show Gist options
  • Save YumaInaura/7a82df5a1dfe3bf90575191ea1ceee5a to your computer and use it in GitHub Desktop.
Save YumaInaura/7a82df5a1dfe3bf90575191ea1ceee5a to your computer and use it in GitHub Desktop.
Gist — Manage in one repository many gists by using git submodule

Gist — Manage in one repository many gists by using git submodule

Gist is a nice service. We can write code so easily and manage files as repository.

But bad points are …

  • Many repository
  • Gist destributes random hash to perticular gists (repositories).
    • So difficult to find or remember contents as repository.

So let's manage them in one normal Github repository.

Create Github normal repository ( for aggregate many gists )

Example:

https://github.com/YumaInaura/gist

Create gist

From web

image.png

Distributed Gist URL example:

https://gist.github.com/YumaInaura/8d52e73dac7dc361745bf568c3c4ba37

Add gist repository to aggregation repository by git submodule

Command:

git submodule add [Gist URL] [Some directory name easy to remember]

Example:

git submodule add https://gist.github.com/YumaInaura/8d52e73dac7dc361745bf568c3c4ba37 understandhing_channel_buffer

Commit and push to aggregation repository

Then we can manage "submodule managed repositories".

Github view

We can find link from aggregation repository to gist.

image.png

image.png

Example page:

https://github.com/YumaInaura/gist/tree/master/go

Clone aggregation repository

Use --recurse-submodules option then we can clone all submodule managed files.

Exmaple:

git clone --recurse-submodules https://github.com/YumaInaura/gist

Careful, If include many submodules, then many clones happens.

@typebrook
Copy link

typebrook commented Jun 19, 2020

@YumaInaura
Great approach! Thank you for sharing this.

The following command should imports all your gists as submodules (replace User by your name)

curl https://api.github.com/users/[USER]/gists |\
jq '.[]|"\(.git_pull_url) \(.description)"' -r |\
while read url desc; do
    repo=$(sed -e 's/[[:punct:]]//g' -e 's/ \+/_/g' <<<"$desc")
    ( git submodule add $url $repo & )
done

@codingedgar
Copy link

codingedgar commented Oct 15, 2020

Thank you! I tried to do this with cloning ssh but didn't work, it works with HTTP tho, is any special step for ssh? (i manage all my normal repositories with ssh, but cant clone gist with ssh)

Update:
I added:

host gist.github.com
 HostName gist.github.com
 IdentityFile {path to key}
 User git

to my ~/.ssh/config and now it's working!

@typebrook
Copy link

@codingedgar
URL for ssh should be [email protected]:[GIST_ID].git

@codingedgar
Copy link

that returns:

[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I'm trying to understand if my ssh keys are conf only for github and not for gists

@typebrook
Copy link

At least my ssh key works both on github.com and gist.github.com. You should check if somethings wrong.

@codingedgar
Copy link

I added:

host gist.github.com
 HostName gist.github.com
 IdentityFile {path to key}
 User git

to my ~/.ssh/config and now it's working

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