3

Is it possible to config git repository not to fetch branches from certain namespaces of the origin repository by default?

What I want is to put my current work in some namespace so that everyone else know it is not ready yet. For example, if I config namespace a like that:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    fetch = +refs/heads/a/*:refs/remotes/origin/a/*
    push = +refs/heads/a/*:refs/heads/a/*
    url = some_git_url

Others would have fetch = +refs/heads/*:refs/remotes/origin/* line but not fetch = +refs/heads/a/*:refs/remotes/origin/a/*. Of course they can fetch branch from my /a/ namespace. But I want that not to happen by default so that my working commits don't clutter others' history graphs.

The problem is that it seems refs/heads/* includes nested namespaces. So when I do git fetch on any machine - I still get everything from /a/ namespace.

Is there a way to config git like I want? To tell git to fetch only immediate branches from refs/heads/?

Ivan Danilov
  • 13,026
  • 5
  • 43
  • 64
  • 1
    Er, how are your commits "cluttering" their history? Normally when viewing history you only do so for a single branch rather than viewing every branch at once... – Amber Jul 22 '11 at 16:22
  • If you're using command line `git log` - yes. But with `gitk` or any other graph visualizer - you see entire history of the repository, not only the branch you're in. – Ivan Danilov Jul 22 '11 at 16:24
  • 1
    Not necessarily. `gitk` can be set to visualize a single branch (and that's often the usage) if desired. – Amber Jul 22 '11 at 16:26
  • Well, I'm fine with seeing every branch. I'm fine with seeing all my working branches. But I don't like to see others' working branches if I don't ask for them explicitly. Setting `gitk` config will turn off _everything_ except current branch. What I want is just not to get refs for others' 'private' branches if it is possible. P.S. And I'm using git extensions btw :) – Ivan Danilov Jul 22 '11 at 16:29
  • The simple way would be to clone the repository into a private directory, and keep your development branches there. But judging by the wording of your question, I'm guessing there's some reason that won't work in your case? –  Jul 22 '11 at 17:49
  • 1
    Well, I could just not push them to remote repository in the first place. But thus way my machine is the only one having them and it is somewhat disturbing if there's some work that cost me more than a day. And having separate repository for everyone on the server that's backing up... it is just too much headache to do. – Ivan Danilov Jul 22 '11 at 18:37
  • [I have a similar question at another SO post.](https://stackoverflow.com/questions/46854505/remote-branch-filters-in-git?noredirect=1#comment80657549_46854505) If anyone ever comes up with a solution that doesn't involve no pushing to remote, please take a look. I too am paranoid of routinely having several days of work living on only a single laptop rather than being backed up to a remote server. – Cloud Oct 20 '17 at 19:40

1 Answers1

0

Keep your working branches locally and only push the shared branches. Ask others to do the same.

That's assuming you're all sharing a central repository as a remote, rather than pushing/pulling to and from each other's local repositories.

Luke H
  • 2,829
  • 25
  • 30