Commit c34b92e
Changed files (2)
docs/how-to-self-host-a-git-repository.md
@@ -0,0 +1,68 @@
+# How to Self-Host a Git Repository?
+
+**Goal**: self-host a Git repository on your server, allowing read-only clones and a web view.
+
+Create a _git_ user on the server where you want to host the repository. This step is optional, but I like to use a
+dedicated user for repository management to keep the system secure and organized.
+
+Create a `~/public` directory, which will serve as the web root. Configure a web server to serve files from this
+directory.
+
+## Bare repo
+
+Create a bare repository inside `~/public`.
+A [bare repository](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols)
+is a special type of Git repository that doesn't have a working directory. It's used for hosting and sharing code
+without the need for a local working copy.
+
+```sh
+git init --bare repo.git
+```
+
+Create a [post-update](https://git-scm.com/docs/git-receive-pack#_post_update_hook) hook with the following content:
+
+```sh
+#!/bin/sh
+exec git update-server-info
+```
+
+Make the hook executable:
+
+```sh
+chmod +x hooks/post-update
+```
+
+## Gitmal hook
+
+Create a [post‑receive](https://git-scm.com/docs/git-receive-pack#_post_receive_hook) hook with the following content:
+
+```sh
+#!/bin/sh
+NO_OUTPUT_DIR_CHECK=1 /path-to/gitmal --output /home/git/public/repo/
+```
+
+Make the hook executable:
+
+```sh
+chmod +x hooks/post-receive
+```
+
+## Publish
+
+Push your local repository to the bare repository on the server using ssh protocol.
+
+```sh
+git remote add origin git@example.com:public/repo.git
+git push origin master
+```
+
+After pushing, git will run gitmal and generate files under `~/public/repo/` directory.
+
+Now you can access the web view at `http://example.com/repo/` and clone the repository:
+
+```sh
+git clone https://example.com/repo.git
+```
+
+Now you have a read-only clone url `https://example.com/repo.git` and read-write clone url
+`git@example.com:public/repo.git`.
README.md
@@ -56,39 +56,9 @@ Gitmal supports different code highlighting themes. You can customize the theme
gitmal --theme github-dark
```
-## Auto‑updates
+## Documentation
-You can automatically regenerate the static files every time you push to a repository by using a `post-receive` hook.
-
-1. **Create a bare repository**
-
- ```sh
- git init --bare ~/myrepo.git
- ```
-
- Add it as a remote and push:
-
- ```sh
- git remote add origin user@server:~/myrepo.git
- ```
-
-2. **Add the post‑receive hook**
-
- Create `~/myrepo.git/hooks/post-receive` with the following contents and make it executable:
-
- ```sh
- #!/bin/sh
-
- NO_OUTPUT_DIR_CHECK=1 /path-to/gitmal --output /var/www/myrepo
- ```
-
- And make it executable:
-
- ```sh
- chmod +x ~/myrepo.git/hooks/post-receive
- ```
-
- Now, every `git push` will trigger a rebuild.
+- [How to Self-Host a Git Repository?](./docs/how-to-self-host-a-git-repository.md)
## License