Git daemon

Git daemon Overview

In a version control system, the daemon is a very simple server for the Git repository. In technical terms, it is a simple TCP command that listens to port which is named as “Default Git Port”. It behaves just like normal servers where it waits for the connection to establish a service and serves if enabled.

The processing starts, and the daemon makes the repositories available to undergo git:// protocol, which seems insecure but is very efficient. When there is a security concern, you need to pull SSH protocol, and the default port that listens to it is 9418.

The configuration of the daemon is done by pushing without authentication. It is quite risky. It should always be performed under LAN enclosed environment, and the sources must be trustworthy. When in doubt, you should use the SSH to push securely.

The git daemon command verifies the directory with the magic file named as “git-magic-export-ok”. This will help Git to refuse the explicitly marked directory to export unless the parameter is set to all. Again, if you pass some directory paths specifying the parameters, you can further restrict them by comparing them from the whitelist that comes along with them.

Moreover, only upload-pack service is enabled by default which is used to serve packages like fetch-pack, ls-remote clients and are invoked using the clone, fetch or pull commands. This method is ideally used for read-only process and is undated from the archives in the server side itself.

Git daemon and its options

Let us now understand the other prospects of the daemon command in Git using various options.

Git daemon comes with tremendous functionalities. For the sake of our process and simplicity, it enables you to create your local server in the machine and you can easily collaborate, push directly and apply to clone. By adding different options with this command you can easily have your server act in different ways.

The daemon command invokes the following options as shown below:

$ git daemon [--verbose] [--syslog] [--export-all]
                [--timeout=<n>] [--init-timeout=<n>] [--max-connections=<n>
                [--strict-paths] [--base-path=<path>] [--base-path-relaxed]
                [--user-path | --user-path=<path>]
                [--interpolated-path=<pathtemplate>]
                [--reuseaddr] [--detach] [--pid-file=<file>]
                [--enable=<service>] [--disable=<service>]
                [--allow-override=<service>] [--forbid-override=<service>]
                [--access-hook=<path>] [--[no-]informative-errors]
                [--inetd |
                [--listen=<host_or_ipaddr>] [--port=<n>]
                [--user=<user> [--group=<group>]]]
                [--log-destination=(stderr|syslog|none)]
                [<directory>…?] 

Let’s breakdown the options as shown below:

[base-path=.]

The above option is used to point to the repository with the current directory using the dot sign. This is done to ensure the inclusion of file in the repository.

[export-all]

The above option is used to share all the available repositories from the base-path option.

[reuseaddr]

This option is used to restart the allowed server from the old connection when time out occurs.

[verbose]

This option is primarily used to check the log details of all the oncoming connections requesting to join server.

[enable/disable=<service>]

This command is used to enable or disable the services across the whole network in the workspace per default.

[receive-pack]

The above option allows you to push anonymously.

Sharing

Consider an instance where you need to share the GitHub repository but you don't have access to it. In this case, you will use the git-daemon command which will enable you to access the repository for sharing. You will just need to define the methods of access. Let us take a look at some of the methods.

Read only access

 $ cd my-repos
 $ ls
 instabot-spoofer- better-twitter instapound
 $ git daemon --base-path=. --export-all --reuseaddr --informative
 errors --verbose
 [8322] Ready to rumble 

This will run the daemon command and establish connection in the form of server. You may see something after this.

 $ git clone git://127.0.0.1/instbot-spoofer
 Cloning into 'instabot-spoofer'...
 remote: Counting objects: ...
 ...
 $ git pull
 Already up-to-date. 

You can replace 127.0.0.1 with your IP to address your local machine.

Push Access

 $ git daemon --base-path=. --export-all --enable=receive-pack --reuseaddr --informative-errors --verbose
[8322] Ready to rumble

This enables you to have push access across branches you want to push. It adds features you want to share and checkout. On further execution, it shows you something like this:

 $ git checkout -b sharing
 # made some changes ...
 $ git commit -am "add sharing feature"
 $ git push -u origin sharing
 ...
 * [new branch]      sharing -> sharing
 ...
 Sharing single repository 

You need to create magic files as shown in the command below:

 $ cd my-repos
 $ ls 
 Instabot-spoofer better-twitter instapound
 $ touch instabot-spoofer/.git/git-daemon-export-ok 

It will initially not be able to export. You need to define the --export-all options. After defining this, you will easily be able to share your single repository. It will output the following:

 $ git clone git://127.0.0.1/instabot-spoofer
 Cloning into 'instabot-spoofer'...
 remote: Counting objects: ..., done.
 ... 

Now your client can easily access the repository.