0

I'm managing git repos with LibGit2Sharp. I have a bare git repository, cloned from remote A. Now I'd like to fetch all changes (i.e. all heads and tags) from remote B and do so:

repository.Network.Fetch("git-url", new[] { "+refs/*:refs/*" })

Or the equivalent (if I'm not mistaken) in git command line:

git fetch "git-url" +refs/*:refs/*

As it happens however remote B is identical to A apart from two new commits not being there (which commits are on two branch heads). This causes the fetch operation to remove those two commits in the clone, basically yielding the same if I'd have cloned from remote B.

What is the correct refspec (or otherwise the correct method) of doing a fetch that will keep local commits intact while allowing new commits to be fetched from remote B? I also tried +refs/*:+refs/* but this will add branch labels to older commits while refs/*:refs/* won't fetch new changes either.

Piedone
  • 2,693
  • 2
  • 24
  • 43

1 Answers1

1

Usually refs from a remote repository go to refs/remotes/<remote_name>/... Thus you can separate references, fetched from different remotes and/or created locally.

That's why a typical fetch reference map looks like: +refs/heads/*:refs/remotes/origin/*

When you choose to map the references directly, one to one, you essentially create a complete mirror of a given remote repo.

user3159253
  • 16,836
  • 3
  • 30
  • 56
  • Thank you. Is there any way to specify an "additive" refspec in this manner? Since the local and remote changes don't touch the same branches the local and remote changes can be merged without issues (but I'd like to keep the repo bare, so don't check out and do an actual merge if possible). – Piedone Dec 11 '15 at 15:13
  • Well, depending on your conditions, and branch naming conventions it may or may not be possible to clearly spearate "local" branches from "remote" ones. But generally it's possible to specify multiple `fetch` specifications, like e.g, described [here](https://git-scm.com/book/en/v2/Git-Internals-The-Refspec). I'm not experienced with `libgit2sharp` but hope those multple refspecs have direct correspondence in the library – user3159253 Dec 13 '15 at 00:54