top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to configure a read-only copy of a remote Git repository on a local server & automatically synchronize its contents?

+1 vote
355 views

How to configure a read-only copy of a remote Git repository on a local server in bare mode and automatically synchronize its contents.

I need to configure a mirror of the repository hosted at another location and the mirrored repository should automatically perform syncing of code at regular intervals.

posted Mar 21, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

A mirror clone is done in a very boring way -- by passing the "--mirror" command-line option to git clone.

In this mode, git clone will configure the resulting local repository in such a way that a mere call to git fetch origin will do a full one-way sync with the source remote repository.

Performing synchronization at regular interval is done via scripting the git fetch origin call making your OS's scheduler run this script using whatever schedule you will configure.

Making the repository read-only is the only tricky part in fact. This mostly amounts to the fact Git itself does not provide any
authentication and authorization, and -- by extension -- access control. To add to the picture, Git repositories may be served using a multitude of options (HTTP, SSH, Git's own server).

The native Git wire protocol (git://) served by the git-daemon program is already read-only unless you tweak the repository's
configuration (see that program's manual page for exact detais), so if you intend to serve your repository using git-daemon, that's all you will need to set up.

Otherwise I'd probably recommend to install a simple pre-receive hook into your repository which would output "Write access denied" to its standard error stream and exit with a non-zero exit code. That is, something as simple as

 #!/bin/sh
 printf 'Write access deniedn' >&2
 exit 1

This will reject all pushes from remote repositories right away. Consult the githooks manual page for more info on hooks.

answer Mar 21, 2016 by Alok Sharma
Similar Questions
+3 votes

When we clone a remote GIT repository, all folders/files will be cloned. This will consume lot of disk space in our local machine.
Is there a way to clone only few folders & exclude others?

This is possible in clearcase snapshot view by changing load rules.

+2 votes

I have a local repository and want to change the master branch to a server git. (I just don't want to delete all files in repository and then clone the server files)How to do that? I guess I have to fetch server data into local directory, merge an push it. Can someone please explain me how to do?

+1 vote

Is it possible to make a git remote pack its repository on every push?

I have tried setting gc.auto to 1 on both the remote and the clients, but so far no push seems to have packed anything.

Do I need to create a push hook on the remote to make it pack?

The reason for this is that I have several git repositorier for org-mode files.

Having a history, and rollback of the history, is more important than having a good history.

The diff of each push is small, the repositories only contain one, or a handful of org-mode files, and some of the org-mode files are quite large.

The remote is git 1:2.1.4-2.1 (debian packge, git --version reports 2.1.4), running on debian 8.0 "jessie".

The clients are various GNU/linux git (whatever comes with the distro out of the box) and Win32 msysgit installations.

0 votes

I have a given server repository at location, let say "A" (URL) I have a new empty repository at another location, let say "B" (URL)

I WOULD LIKE TO COPY ALL CONTENT FROM A TO B.

  • In a local clone of B I did a "git pull A" but I've got the "master" branch only.
  • In a local clone of B I cannot say "git pull --all A"

COULD YOU PLEASE PROVIDE THE SINGLE STEPS ON HOW TO DO THIS?

  • please: not rsync like stuff, I would prefer the git way -> I hope there's one
  • please: a few comments would be great
...