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.

1 Answer 1

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.

2
  • 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, 2015 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. I'm not experienced with libgit2sharp but hope those multple refspecs have direct correspondence in the library Dec 13, 2015 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.