Home Git repos in Nextcloud
Post
Cancel

Git repos in Nextcloud

The usual solution to put git repositories on a remote server is to transfer and sync them with SSH. However, in cases where setting up the SSH connection is troublesome (e.g. lack of SSH server or lack of keys in the client system), it can be useful to use Nextcloud as an alternative to mirror git repositories and/or syncronize them accross computers.

Nextcloud is not designed to be used as a source code management tool, if you need one check Github, GitLab or Gitea.

Putting a git repository in Nextcloud can be achieved quite easily by placing the bare repository of your repo in a local folder and sync it with your Nextcloud instance. Syncronization speed is on the low end, so this solution is not meant for real-time syncronization of repositories with a lot of activity, but is a viable option for small private repositories.

  1. Sync a local folder with your Nextcloud instance using any of the Nextcloud clients. In the following, this folder will be ~/Public/Nextcloud

  2. Put a git bare repository in the folder synced with Nextcloud

    • Exporting the bare repository of an existing repository
      1
      
        $ git clone --bare my_project ~/Public/Nextcloud/my_project.git
      
    • Inititalizing a new git repository from a local bare repository
      1
      2
      
        $ git init --bare ~/Public/Nextcloud/my_project.git
        $ git clone ~/Public/Nextcloud/my_project.git
      
  3. Check tracked remotes in your repository

    1
    2
    3
    4
    
     $ cd my_project
     $ git remote -v
     origin  /home/user/Public/Nextcloud/my_project.git (fetch)
     origin  /home/user/Public/Nextcloud/my_project.git (push)
    

    Use a different name than origin for the remote repository in Nextcloud to add it as a non-default remote (e.g. in case it is used as backup).

This post is licensed under CC BY 4.0 by the author.