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.
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.
Sync a local folder with your Nextcloud instance using any of the Nextcloud clients. In the following, this folder will be
~/Public/Nextcloud
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
- Exporting the bare repository of an existing repository
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).