How To Enable Git Protocol on GitLab CE

By default GitLab CE only supports ssh:// or https:// connections for read/write operations on your GitLab projects.  If you have a private server and you want to enable read only access over the git:// protocol you can use this method.  It is not recommended using this is you have a public facing server unless you are prepared to handle the traffic that may result.catalogicon-gitlab

Please note that I am running my GitLab on an Ubuntu 14 server.  The method I describe below will not work on CentOS or RedHat-like OS’s.

Step 1: Create local-git-daemon.conf File

You do not need to install anything.  If you have GitLab installed the Git Daemon already exists on your server.

  1.  At the command prompt on your GitLab server, type:
sudo nano /etc/init/local-git-daemon.conf

Note: I prefer nano as my editor.  You can use whatever editor you wish.

2.  Inside the document place the following:

start on startup
stop on shutdown
exec /usr/bin/git daemon \
   --user=git --group=git --enable=upload-pack \
   --syslog  --verbose  --reuseaddr --base-path-relaxed \
   --base-path=/path/to/gitlab/repositories \
   /path/to/gitlab/repositories \
respawn

Notes about the above: I don’t know why you have to list the path to your repositories twice, but you do.  Also some of the settings I listed could be left out as they are the default for the git daemon.  However, just in case those defaults have been modified elsewhere, I provided them here.

3.  Save the file.

Step 2: Make It Start At Boot

1.  At the command prompt, type:

sudo nano /etc/rc.local

2.  Add the following line:

sudo initctl start local-git-daemon

Step 3: Start The Daemon

At the command prompt, type:

sudo initctl start local-git-daemon

Step 4: Enable Repositories for Export

If you want all of your repositories to be exportable then just add “–export all” to the local-git-daemon.conf file and there is nothing further to do.

If you only one to export particular repositories you will have to create a file called git-daemon-export-ok in the target repositories.  In the example below I have a group called “test” and a project called “test” that is inside that group.

cd /path/to/gitlab/repositories/test/test.git
touch git-daemon-export-ok
chown git:git git-daemon-export-ok

Step 5: Test

From terminal on another computer:

git ls-remote git://mygitlab.mydomain.com/test/test.git

results:

4eed18d374f62508cb50e123fda295bd935b1230 HEAD
4eed18d374f62508cb50e123fda295bd935b1230 refs/heads/master
Follow by Email
Facebook
Google+
http://cloudlady911.com/index.php/2016/11/26/how-to-enable-git-protocol-on-gitlab-ce/
LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *