Exclude git branches from syncronisation after initial import

I’m mirroring a svn depo, is it possible to have some branches only on the git side after the initial import? I’d like to exclude all the branches named feature/something but reading the documentation it’s unclear if excludebranches applies to the git side as well as the svn side

Hello Angelo,

do I understand correctly you want to include the feature/something branches in the initial replication so that they appear in Git, but stop mirroring them after the initial replication so that both SVN and Git counterparts are still present in SVN and Git respectively, but are no synchronised?
If so, then I’m afraid the svn.excludeBranches will not much of a help since adding a branch into the exclusion after it was imported during the initial import would require the repository rebuild which will just re-create the Git repository without those drives.
I’m afraid there is no standard way to get this done. It’s possible, however, but with some trick that allows to bypass standard SubGit’s algorithms. To stop mirroring a branch, stop the mirror with subgit shutdown command after the initial import finishes, add the exclusion setting:

    excludeBranches = feature/something

in the same in both REPO/subgit/config AND REPO/subgit/.run/config files, and then start the mirror again:

subgit install REPO

This will effectively stop the excluded branches synchronisation, but leave the branches in Git. But I must warn you here that this is not safe setup and in some situations (when a commit from an excluded branch is merged to a mirrored branch, in the first place) may break the mirror.

Hello Ildar,
I already did the initial setup with all my svn branches, there are no “feature” branches on svn.
I want to be able to create git branches named “feature/something” and keep them only on the git repo, without syncronising them on svn.


Hello Angelo,

ok, then the main idea is to have Git branches that are not covered by SubGit’s mapping configuration, so if the feature namespace is not mapped, then those branches are Git-only branches.

my current mapping is
branches = branches/:refs/heads/

if I use the exclude branches
excludeBranches = feature/*
will it keep the feature branches only on the git repo or not?
In alternative can I change the branches mapping now that I already have finished the initial sync without having to regenerate everything?

Hello Angelo,

the excludeBranches setting take an SVN path as a value, so if it’s set like follows:

    excludeBranches = feature/*

it means that SVN branches that reside in the feature directory will be excluded from the mirror; but since there is no such path in your mapping, this excludeBranches setting will do nothing.

What I was trying to express was the Git namespaces approach. The idea behind this is that SubGit only mirrors those branches that are covered by the mapping and that usually the mapping covers default Git namespace. The mapping you have:

branches = branches/*:refs/heads/*

covers all the references in refs/heads which is the place where Git creates branches by default, so its you create a branch like this:

git checkout -b newbranch

the reference for this branch will be refs/heads/newbranch thus being covered by the mapping and thus being mirrored. But if you create a new branch in another namespace:

git checkout -b 'feature/newbranch'

the reference will be refs/heads/feature/newbranch which is not covered by the mapping and thus won’t be mirrored. So with the mapping you mentioned, all the Git branches in namespaces will be effectively Git-only branches and only branches in ‘refs/heads’ are mirrored.

It’s also possible to go with excludeBranches, though, but in a slightly different way than you mentioned; an exclusion setting like this:

excludeBranches = branches/feature*

will exclude branches which names start with feature from the mirror, no matter in SVN or in Git were they created. In this case it is not needed to create Git branches in a separate namespaces since they are being excluded by names.

Hope this will help.

1 Like