0

I have my own GIT server, in which I did a 'bare clone' of a public repo. Let's call PUB the public repo, and LOC the bare clone on my own server. I use LOC as remote for developing, creating my own branches that are not present in PUB. Then I push my branches to LOC.

I want to fetch any new content from PUB to LOC but I do not want any of my own branches to be pushed from LOC to PUB.

I can do none operation on PUB since it is out of my control. I can do any operation on LOC instead.

For the purposes I described I have a script, run every night, that executes:

git --git-dir ${LOC_PATH} remote update --prune

If I clone PUB to LOC using

git clone --mirror <remote_repo>

then at the script execution my own branches are erased from LOC.

If I clone PUB to LOC using

git clone --bare <remote_repo>

then the script seems to fetch successfully PUB to LOC (that's what the command output suggests); but observing LOC content with a browser or fetching LOC to my PC I don't see in the log any new commit that I know to be present in PUB.

Reading the answers on other stackoverflow questions, it seems that the right command is:

git --git-dir ${LOC_PATH} fetch --all

but at present time I stick to git ... remote update ... since it should do an implicit fetch operation.

Is there any solution for automatically keep up to date this quirky form of mirroring?

I looked at:

and some other sites found on internet. Obviously I found no viable solution.

Flinco
  • 1
  • 1
    You know the correct way is to use `git fetch` yet you keep doing something else, knowing it is the wrong way. And now you want us to help you... do what? Did I summarize your question correctly or am I completely mistaken? – Friedrich Feb 23 '23 at 14:25
  • @friedrich, you are close to the truth when you say that I am doing something else knowing it is the wrong way. :-) The man page of `git-remote` reports that the `update` command `Fetch updates for remotes or ...`. So, just before moving from `remote update` to `fetch`, I would like that someone explain me why `update remote` does not _fetch_ (that is what I expect). – Flinco Feb 23 '23 at 16:35

1 Answers1

0

I checked on my machine with some repos and came to the following conclusions:

  • git remote update indeed performs an implicit fetch and ...
  • git fetch alone won't work for the problem, either.

After any of the above operations, FETCH_HEAD is created and points to the newest commit on the public remote (called PUB in the question). As your local repo (called LOC) is a bare one, it is not possible to merge or pull on it. When pulling from LOC, the newest commits are just not there.

The brute force solution to apply FETCH_HEAD is to simply git reset --soft FETCH_HEAD on LOC. Afterwards, you will see all the new commits.

The other solution (as mentioned in the answer to How do I update my bare repo?) is to use git fetch *:* in the first place. I could not find a way to pass *:* to git submodule update but maybe there is one.

As mentioned in the comments, git clone's --mirror option does exactly what it's supposed to do: it mirrors the remote. Any additional branches or commits are thrown out. So this is good for backups but bad if you want to have something that's not an exact replica.

Friedrich
  • 2,011
  • 2
  • 17
  • 19