Reference a git repo

Im looking for a way to reference git repositories inside of obsidian. I haven’t been able to find what im looking for online anywhere. I’m looking for something better than iFrames to do this. If it does exist at all

Can you describe in more detail what you want to do?

Oh wow I didnt get this notification. Sorry. Thank you for your response.

I have been copying alot of code blocks and files into Obsidian to take note of concepts as used in practice as I learn how to program. I was wondering if there was a plugin that would let me link sections of the code so I could 1. view and import it easier. and 2. Open the file in another program via a link. I referenced git as I didnt understand at the time that repositories are separate from git the source control system

Thank you. I realize this still might not make any sense but if there are any plugins or ways to build this myself that would be greatly appreciated.

I’m not sure if this answers your questions, but contemplating on commenting and executing code from within Obsidian I found this combo of plugins:

  • Execute Code – Which allows you to execute code snippets in code blocks in your note
  • Obsidian Code Styler – which lets you style codeblocks and inline code in both editing mode and reading mode

Neither of these will help you import the code into Obsidian, nor link to another program to open the code with, so you’ll possibly need to use some web importer (or just copy-paste) to get the code. I haven’t seen any plugins allowing you to do the import from within Obsidian, but there are many plugins which I’m not aware of.

So my take on what I think is your use case would be to use some web clipper/importer to put the code into my vault, and then use either or both of the plugins mentioned to execute/talk/discuss/elaborate on the code.

Hi I’m the maintainer of the Code Styler plug-in. I could add in this functionality or maybe make a new plugin that did something along these lines if it was helpful but I’m curious about how you envisage this working.

  • Would the user use a command to import a git repository which would clone the whole repository locally and create some sort of index note?
    • I can see there being issues with users who use git to manage their obsidian vault regarding nested modules
    • it also seems like this could potentially involve downloading a lot of files to reference maybe just 1 file
  • would you like codeblocks that specify say a GitHub or gitlab or whatever repository, a specific file in the file tree and maybe some additional line parameters and render the desired code section on command?
    • this would not work online so
  • some sort of cached intermediate version which clones only the required files on first view of the code block and then has to be updated on some user specified basis, manually or when you review that note. This could work offline but wouldn’t update or show new queries obviously but wouldn’t necessarily be up to date.

Please let me know because this does sound interesting.

I was personally thinking referencing a repository to have an up to date version of whatever code is referenced.

Another reason is to make that note available on other computers that wouldn’t necessarily have the repo. Say a published notes page.

I find myself unsure still as of now what I truly envision for this, I will try and update a list of ideas at a later date

1 Like

Not being the OP, but to me this seems to be the better option. Given that part of the purpose is to take note of concepts and for use in learning to program, I’d say that needing it to be manually updated is benefit, as you then know when it updates, and can check that you are still viewing the correct portion of the code.

This could possibly also be useful when working/documenting bugs and so on, as you could then refer to the code at a given time.

Having something similar to the search result from GitHub would be a very fancy variant, like the image below where I searched for “example” in the Obsidian Code Styler plugin:

Nice aspects of such a view includes:

  • Having a proper link to the original document
  • Using the title line to add buttons to update the code
  • And one could use a link similar to that shown to specify which block to show… Possibly with the line number combinations as offered in the plugin.

On second thought i agree with this. Both in the reasoning behind it and the possible implementation. As much as i would like to implement it i do not even know where to begin. Like i said, I am a beginner. I understand that there is a example plugin in the docs…?

Including the full code? If you’re thinking about distribution then I’m pretty sure an iframe is the best method. But what do you think of the three approaches I outlined. Personally I like the idea of the third one, do you see any issues with it? It wouldn’t use local files if you do have the repository downloaded somewhere since that would be arbitrary file access outside the vault but it be that different computers with the same plugin and same codeblock/reference see the same thing. But yeah, always happy to hear your ideas!

I’m actually quite interested in adding this to Code Styler! If you want to make your own plugin feel free, I’d be happy to contribute and likewise if you want to contribute to Code Styler and help implement this I’d welcome any help! That and the potential to include references to local files would be a great addition. Sorry I didn’t see this post when I replied to your previous one!

I think I agree with this manual updating. Though I think the option for automatic updating would be helpful too for some.

Completely agree with linking to the actual repo in the title (I’d probably implement this as a the code block title being automatically set to the repo and file and line number and also implemented as an external link to the suggested url). Adding a button to the title line to update the code manually would also be a good idea.

1 Like

I don’t know anything about this type of coding/programing. I would like to contribute however I don’t even know what languages are used or even where to begin.

I’ve actually gone and just implemented this more or less in Code Styler. Still fine tuning some of the details such as updating and removing old files but the basic concept works! Feel free to have a look at the reference based files in the repo but no obligation ofc.

On that note, I’d actually love some suggestions on some things:

  • How/When the plugin should remove files
    • If there is no reference block, the downloaded file should be deleted presumably? This could be quite hard to check, would appreciate any advice
  • Updating
    • Currently leaning towards a setting for frequency (can also be never) and on plugin load, check if any files are outdated, if so update them. Also an additional button on the code block for manual updating on click.
  • Showing Information
    • Currently I have lots of info like repo, author, file name, commit sha, branch etc. What is the best way to show that information as it can end up taking lots of space

I’m suggesting you have a specific folder, defined in settings for the downloaded file, and then it shouldn’t be that hard to write a cleanup query which you could run from the settings screen?

I’d like to set that to manual, and only use when I’d request it. But that’s me. Maybe have “manual”, “on load” and a frequency based variant? In addition to the button in the view.

You could even let the update procedure do the clean up of non-referenced files.

The downside to any frequency based updating is that it would mean that your Obsidian would require and use the internet at a random interval, for something you might have forgotten that you even had in your vault.

I prefer to know when and why my devices download stuff, so my preference is rather to have a timestamp related to when it was downloaded allowing me to decide when it’s appropriate to download it again.

Keeping the main view sleek and clean, and then rather provide a modal/popup to show all the extra information could be an option. Maybe with a tooltip showing the full repository link, and just the filename in the main view.

That’s my two cents on the topic, @mayurankv .

1 Like


Currently I have it set to look like this with what will be customisable colours for repo and branch/commit:

(zsh prompt style kind of haha)

That info is automatically found via the link. The only additional things I want to add are a timestamp for when it was updated and an icon indicating GitHub vs gitlab vs bitbucket vs sourceforge etc.


Yeah I think what you say makes sense, the default value should be never.


I’m currently writing files to the plugin folder itself since I think adding files that obsidian can’t see directly to the vault path wouldn’t be good management. Also personally I’d rather have it all hidden away than have some Code-Styler-Github-Files folder defined somewhere. One alternative is downloading the file next to the file where the reference was defined which could help with cleaning but I’m not sure if that’s as nice. How would you suggest writing the query for cleanup? You’d have to potentially iterate through all files, find the code blocks, find the associated filed and delete the remaining ones, I’m not too sure how to do this efficiently.

Thanks for your input, really helpful!

This is actually really amazing. I don’t know type script but i would like to test. If i may ask how would i test this?

Keeping it out of the main vault seems like a good choice.

I reckon that since you have special means to get these files, it would be easy to also keep track of which codeblocks has used them at one point. So when you want to clean up, you could check this cache of where you’ve encountered these codeblocks and then scan each of those files to verify if they still exist or not. That shouldn’t be that expensive, and you wouldn’t need to scan the entire vault since you kept track of the usage.

If you give me a few days, I’ll probably have a working version ready for testing. Got some coursework I need to get done but after that, I’ll polish it off. The main stuff is done now, just the bells and whistles and making sure everything works properly. If you really fancy, you can install the Obsidian BRAT plugin and install the main branch of code styler via that and try things out.

1 Like

All good! I think I’m going to check that out. Thank you so much

1 Like