Exposing GIT repository via SSH and HTTP
You don't need a git hosting service to manage and share your git repo. All you need is a server which is:
- accessible via SSH (to yourself, not others), for pushing changes, and
- has a public accessible HTTP server (for others to clone)
Firstly, on the remote server, let's prepare a bare repo:
1 | mkdir repo.git; cd repo.git |
Also, move repo.git
directory to a place under HTTP server directory. I put it under ~/html/git/
so there can host multiple git repos.
Now, with SSH, you should be able to push changes via SSH already:
1 | # In your git repo: |
Now, exposing the repo to HTTP mostly following this guide:
1 | # in the bare repo: |
Note:
- the hook calls update-server-info, so everytime there's a push, the server info is updated (needed to serve the repo via HTTP).
- the default hook script seems to have a bug in it:
1 | exec git-update-server-info |
On my system git-update-server-info
does not exit. So I've to change it to
1 | exec git update-server-info |
- I host the repo on a public unix system, so I have
umask 077
. So, in order for the updated git repo to be always exposed to public (HTTP), I need tochmod
all subdir/files togo+rX
. So I also do this in the post-update hook:
1 | # hooks/post-update |
-
exec must be in a sub-shell, otherwise commands following it won't run echo "Updating server info..."
-
the hook is run in a bare repo's root dir (link)
-
When you push remotely, the output of the hooks are shown in the
git push
output.
After these steps, you can pull it from HTTP:
- Pull it from HTTP
1 | git pull http://$SERVER_URL/path/to/repo_dir repo.http |
- Test that repo changes and file permissions are are indeed updated via the hooks:
1 | # Make some change to the repo and push via SSH |
Then pull via HTTP again
1 | # in repo.http/ |
Make sure you see the update