{"id":19049554,"url":"https://github.com/crhntr/explore-go-git-wasm","last_synced_at":"2025-09-07T04:31:44.085Z","repository":{"id":130824527,"uuid":"232694224","full_name":"crhntr/explore-go-git-wasm","owner":"crhntr","description":"Is it currently possible to use go-git in the browser? Not really... but I made it work.","archived":false,"fork":false,"pushed_at":"2023-02-25T07:04:18.000Z","size":765,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-30T19:38:26.109Z","etag":null,"topics":["git","go","wasm"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crhntr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-09T01:22:48.000Z","updated_at":"2021-01-20T14:42:44.000Z","dependencies_parsed_at":"2023-05-18T23:45:36.745Z","dependency_job_id":null,"html_url":"https://github.com/crhntr/explore-go-git-wasm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crhntr%2Fexplore-go-git-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crhntr%2Fexplore-go-git-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crhntr%2Fexplore-go-git-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crhntr%2Fexplore-go-git-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crhntr","download_url":"https://codeload.github.com/crhntr/explore-go-git-wasm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232176788,"owners_count":18483775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","go","wasm"],"created_at":"2024-11-08T23:11:15.501Z","updated_at":"2025-01-02T09:27:28.883Z","avatar_url":"https://github.com/crhntr.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Using the go-git package in the browser\n\n## Abstract\n\nGo now supports [Web Assembly]((https://github.com/golang/go/wiki/WebAssembly)), which runs in most browsers.\nGo-Git supports fully [in memory](https://github.com/go-git/go-git#in-memory-example) plumbing and \"ceramic\" operations.\nGit can be hard to understand and DOM (document object model) visualizations of the state could be really cool.\nI tried to compile a Go program that imports and uses the go-git package.\nBy refactoring when and how the osfs package gets imported in go-git we can use git in the browser.\n\nI have a tagged release here with the required go-git changes: https://github.com/crhntr/go-git/releases/tag/wip-js-wasm\n\nTo get my proof-of-concept release run `go get github.com/crhntr/go-git@wip-js-wasm`\nand add `replace github.com/go-git/go-git/v5 v5.2.0 =\u003e  github.com/crhntr/go-git/v5 \u003cthe version you see in the 'go get' output\u003e` to your module file. \n\n## Methodology\n\n- Get imported modules\n\n  `go mod vendor`\n\n- Find usages of packages that do non-wasm-supproted os syscalls\n\n  go-git abstracts the filesystem and OS interactions using the go-billy Filesystem. \n  The go-billy/inmem Filesystem works in browser wasm environments [see github.com/crhntr/explore-go-billy-wasm](https://github.com/crhntr/explore-go-billy-wasm).\n  \n  The go-billy implementation that is not supported in the browser is [go-billy/osfs](https://github.com/go-git/go-billy/tree/master/osfs), which wraps the standard library filesystem package.\n  \n  To find uses of osfs, I ran the following\n  \n  ```sh\n  cd vendor\n  ag gopkg.in/src-d/go-billy.v4/osfs\n  ```\n  \n  ```\n  github.com/go-git/go-git/v5/remote.go\n  9:      \"github.com/go-git/go-billy/v5/osfs\"\n  \n  github.com/go-git/go-git/v5/storage/filesystem/dotgit/dotgit.go\n  17:     \"github.com/go-git/go-billy/v5/osfs\"\n  \n  github.com/go-git/go-git/v5/plumbing/transport/server/loader.go\n  10:     \"github.com/go-git/go-billy/v5/osfs\"\n  \n  github.com/go-git/go-git/v5/repository.go\n  33:     \"github.com/go-git/go-billy/v5/osfs\"\n  ```\n  \n  The osfs package is used in the following files:\n  \n  In repository.go\n  - func PlainInit\n  - func dotGitToOSFilesystems\n  - func dotGitFileToOSFilesystem\n  \n  In remote.go\n  - func PushContext\n  \n  In storage/filesystem/dotgit.go\n  - func Alternates\n  \n  I then factored out the usages of osfs (see diff here: https://github.com/crhntr/go-git/commit/09378a6e8d4bb3078f6f4de990c22c40077bafd5).\n\n  I did not check for network usage that would not be supported in Go wasm environments.\n\n## Results\n\nThere are a few imports that do not allow go-git to be imported in a Go program compiled for the browser. Some refactors could make this work.\n\n## Developer Notes\n\n`./start.sh` is a script that starts a web server that loads the wasm into the browser.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrhntr%2Fexplore-go-git-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrhntr%2Fexplore-go-git-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrhntr%2Fexplore-go-git-wasm/lists"}