Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/joshnuss/git-ssh-server

A small git/ssh server for hosting repos
https://github.com/joshnuss/git-ssh-server

git hosting node ssh

Last synced: 25 days ago
JSON representation

A small git/ssh server for hosting repos

Awesome Lists containing this project

README

        

Example GIT+SSH Server
----------------------

A small git/ssh server for hosting repos and running custom logic after push.

# Features

- `git push`, `git pull` & `git clone` are supported.
- Authentication is done via public keys exclusively. (no passwords allowed)
- Repos & public keys are stored on disk.
- Repos are automatically created on-demand (first push).
- Server-side hooks like `pre-receive`, `update` & `post-receive` can be applied to all repos.

## Setup

Get the latest code:

```bash
git clone joshnuss/git-ssh-server
cd git-ssh-server
yarn
```

Create a host key with a passphrase:

```bash
ssh-keygen host.key
```

Add `.pub` public keys to the `keys` folder:

```bash
# if using locally
cp ~/.ssh/id_rsa.pub keys/me.pub
```

Add git hooks like `pre-receive`, `update` & `post-receive` to the `hooks` folder (optional).

Example `post-receive` hook:

```bash
#!/bin/bash

while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "Master ref received. Deploying master branch to production..."
git --work-tree=/var/www/html --git-dir=/home/demo/proj checkout -f
else
echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server."
fi
done
```

Hooks are symlinked on first push.

## Usage

Start the server:

```bash
PORT=22755 ADDRESS=localhost PASSPHRASE=foobar yarn start
```

For an existing repo:

```bash
# add a remote
git remote add hosting ssh://git@localhost:22755/your-repo-name

# OR if you're using a standard SSH port 22
git remote add hosting [email protected]/your-repo-name

# push to remote
git push hosting master

# pull from remote
git pull hosting master
```

Or clone a new repo:

```bash
# clone from remote
git clone ssh://[email protected]:22755/your-repo-name

# OR if using standard SSH port 22
git clone [email protected]/your-repo-name
```

## License

MIT