Monday, April 30, 2018

Set up my own git server.

The procedure to setup a git server

1. Create few directories
$ mkdir -p ~/gitserver/repos ~/gitserver/keys
2. Create an empty project named myrepo
$ cd ~/gitserver/repos
$ git init --bare myrepo.git
3. Add some public keys to the keys directory ~/gitserver/keys by simply copy pub key files in that directory.

4. Run the following command to start up the git server:
docker run -d -p 2222:22 \
  --restart unless-stopped \
  -v /home/ibmadmin/gitserver/repos:/git-server/repos \
  -v /home/ibmadmin/gitserver/keys:/git-server/keys \
  --name gitserver jkarlos/git-server-docker
5. Now access the project at this url:
ssh://git@9.42.91.228:2222/git-server/repos/myrepo.git
Notice that the user for this git server is called "git".

The procedure to setup a mirror repo of another repo. In the following example, mirror.git is the mirror of the original.git repo.

Do the following initially:
git clone --mirror git@example.com/original.git
cd original.git
git push --mirror git@example.com/mirror.git 
Do not delete the original.git, keep that directory. When there is an update, make sure that the private key which matches the public key used for the git server was added to ssh-agent, then simply do the following:
cd original.git
git fetch
git push --mirror git@example.com/mirror.git

No comments:

Post a Comment