Setting up Git source control on a QNAP NAS

When I start a new project, the first thing I do is set up source control. Source control is key!
I know all my source code is safe and when I make mistakes I can easily do a rollback.

So why not take it serious and use Git?
GitHub is great, but it is not free when using private repositories. Tho I’m a big fan of open source, not all my projects are open source.

So I wanted to configure Git on my NAS, an old QNAP TS-410 (currently running on firmware 4.2.0).
This is how I configured Git for a QNAP NAS.

Install Git

First of all, install the QNAP package from the app center (currently version 2.1.0) and make sure it is turned on.

There seems to be something wrong with the QNAP Git package, because a manual action is required.
open a ssh connection to your NAS.

If you’re not familiar with ssh, you can download a client (f.e. putty) and open a new connection by entering the IP of your NAS.

now login with your admin account and enter the following command:


#  cd /usr/bin
#  ln -s /Apps/git/bin/git-upload-pack
#  ln -s /Apps/git/bin/git-receive-pack

This fixes an issue with the git-upload-pack and git-receive-pack not being found.

Hosting your repositories

Next, create a new share for your repositories.
I created a new share named ‘git’, but you’re free to choose.

Again, open an ssh connection and go to the just created share:

#  cd /share/MD0_DATA/git

if this does not work, the MD0_DATA folder is probably different. go to the /share folder and check the folder name with the following command:

#  ls -la

This will show a full list of all items and you can figure out what the right name is.

in the ‘git’ folder, enter the following command to create a new repository:

git init --bare NameOfMyRepository

This creates a new repository with the name ‘NameOfMyRepository’. It will automatically create a new subfolder with an identical name.

Cloning the repository

On your development machine, open your git tool and go to the directory where you want to work.
Now enter the following command:

git clone admin@YourIP:/share/git/NameOfMyRepository

This will ask for the admin’s password.
You can also use auto login by generating a ssh keyfile, but I do not want that for security reasons.

Once entered, the repository is cloned in a folder named ‘NameOfMyRepository’ and you’re good to go!

The Git controls integrated in VS2015 do not work with ssh yet, but the guys are working on it. You can read about it here

The following two tabs change content below.
I'm a software developer from Utrecht. Interested in DDD, continuous delivery, new technologies & frameworks.

Latest posts by Vincent Keizer (see all)

28 Replies to “Setting up Git source control on a QNAP NAS”

    1. Hi Simon,

      Thanks for your comment.
      What do you mean with source tree? Do you mean the integrated source control in Visual Studio?
      That isn’t supported yet. You can use the git command line to push and pull.
      This isn’t ideal, I know. I’m still trying to find a better solution for this.

        1. Hi Simon,
          I also use SourceTree and using the following syntax as a git URL works fine for me:
          ///git/
          … if you created “git” as your share name as proposed by Vincent.

  1. hi! thanks for sharing this. i tried it but got an error while trying to clone the repo under windows:
    $ git clone admin@192.168.1.111:/share/git/MyFirstRepo
    Cloning into ‘MyFirstRepo’…
    FATAL ERROR: Network error: Connection refused
    fatal: Could not read from remote repository.
    Please make sure you have the correct access rights
    and the repository exists.
    the repo does exist. i never get asked for the admin password. reading your tutorial i thought i’d be happy if i could use another user than the admin. but it’s not working even with the most privileged user…

    1. Hi chris,

      It is not mandatory to use the admin user, you can use a different user for it as long as it has enough privileges.
      I had the same error before I fixed the two git packages (git-upload-pack and git-receive-pack). Did fixing these packaging went correctly? No errors?

      1. hi vincent, if by fixing you mean creating those two links in the /usr/bin directory, yes i did that 🙁 i’m not getting any errors other than that one i mentioned in my previous post. thanks for helping me out here 🙂

        1. Same problem here on TS-251.
          All step done:
          – installed GIT 2.1.0 from QNAP repository
          – made link with no error
          – share created (name: git)
          – installed Git for Windows on my machine
          – issued command: git clone admin@192.168.1.200:/share/git/testRepo
          result:
          Cloning into ‘testRepo’…
          fatal: protocol error: bad line length character: admi

          – issued command git clone admin:admin@192.168.1.200:/share/git/testRepo
          result:
          Cloning into ‘testRepo’…
          Unable to open connection:
          Host does not existfatal: Could not read from remote repository.

          Please make sure you have the correct access rights
          and the repository exists.

          – issued command git clone admin@192.168.1.200:/git/testRepo
          result:
          Cloning into ‘testRepo’…
          fatal: protocol error: bad line length character: admi (is not an error, it report me as admi and not admin)

          Where I am wrong?
          Some hint?

  2. Thanks for this clear tutorial! Just getting started with GIT. Is it correct that the repository on the QNAP does will not contain the actual source files?

    1. Hi Jeroen, Thanks. It does actually store the file, they are stored in the objects folder. But it is not that simple. You cannot just browse through the objects folder and find all your files. The objects folder contains all your commit, trees, blobs and tags. They are all compressed with zlib, extracting them will give you your content. Though I should suggest you use the git tools to retrieve your files.

    1. Hi Simon, you could use port forwarding on your router and forward the ssh port to your NAS.
      This does bring a security risk, because this port will be open for everyone, so make sure you’ve got proper security

      1. Okay, Thanks for the info,
        I am looking for an way to push it to an continous integration server.
        with an trigger or something.

  3. Hi,

    How can we do this without admin account ?
    Also how do a regular user can clone the repo ? I am having permission issue

    Thanks,

    PS: Your Tutorial is awesome

    1. Hi Bastien,

      Thanks! Just make sure your account has sufficient rights to your share and replace the admin account in the clone command with your account.

      F.e.

      git clone youraccount@YourIP:/share/git/NameOfMyRepository

      1. Hi Vincent. Thanks for easy to follow tutorial. I made this work on my QNAP. But I ran into one problem.

        I cannot clone with non-admin account. I tried what you have mentioned above. It gives me a “permission denied” error. I don’t know much about the inner workings but could this be due to restriction on SSH access? Error log shows ” Login Fail (SSH)”.

        The user has RW access to the folder, I even changed owner. Nothing worked. Is this not possible or did I miss something?

        Thanks,
        Suresh

    1. Hi Patrik,

      You’re right, the package seems to be gone from the QNAP package repository. I think it is removed by the Container station app. This should make it possible to install GitLab. Unfortunately, this app isn’t available for my QNAP NAS.
      Thanks for posting the link!

      1. I just set up Gitlab using container station on mine. Easy! Just need to work out how to get gitlab to successfully send emails – for setting up new users!

        1. I am desperately trying to get gitlab to work on my QNAP TS-453 Pro. I have installed from Container Station, rebooted, then trying to go to the url:10080. Only response I get is
          502
          Whoops, GitLab is taking too much time to respond.
          Try refreshing the page, or going back and attempting the action again.
          Please contact your GitLab administrator if this problem persists.

          Well, I am the admin… I have searched for this and the main issue I find is memory – but it has almost 8 GB available so that cannot be issue.

          Any ideas for what may be the issue?

  4. Strange each time I want to git clone (different days) I have to run command s
    # ln -s /Apps/git/bin/git-upload-pack
    # ln -s /Apps/git/bin/git-receive-pack
    over and over… it does work after these.

  5. GIT has silently been removed from app store and seems no longer to be provided as an official Qnap app therefor you need to install it either manually or via qpkg/ipkg instead.

  6. Hi,

    I tried your way, downloaded app from dropbox, but even though I’ve installed git using appcenter, I get the message:

    -sh: git: command not found

    when trying to create the repo. Do you know how to solve this?

    Thanks in advance.

Leave a Reply

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