# Git private branch Feature Suggestion

5 messages from 2025-09-10 to 2025-09-11. Participants: ynckz, rsbecker@nexbridge.com, brian m. carlson, Henrique Soares, Kristoffer Haugsbakk.
Thread: https://gitlist.dev/t/64126

## ynckz, 2025-09-10 23:28

Subject: Git private branch Feature Suggestion
Message-ID: <CAGyVUB5QLV+HQMWT+0kDu1_H0uXHK7kTy35WqhXQaETZ5if5EQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAGyVUB5QLV%2BHQMWT%2B0kDu1_H0uXHK7kTy35WqhXQaETZ5if5EQ%40mail.gmail.com

```
Hi Git developers,

I have a request for you. Could you please add private branches? This
is a really useful thing.
Imagine that you want to publish your project as open source, but you
need to hide the .env file in a separate repository. It's easier to do
everything in one repository, but in a different branch. Maybe there
is another way, and I'm just dumb as fuck, but here's another example:
Say you don't want to release a new feature yet. To do so, create a
private branch, make the feature there, then merge it into the main
branch.

Maybe I'm a dumb ass, and don't need to ask this of you, but GitLab,
etc., anyway, I'd appreciate it if you could add this feature.

```

## rsbecker@nexbridge.com, 2025-09-10 23:54

Subject: RE: Git private branch Feature Suggestion
Message-ID: <061501dc22ae$45ac35c0$d104a140$@nexbridge.com>
URL: https://gitlist.dev/e/061501dc22ae%2445ac35c0%24d104a140%24%40nexbridge.com
In-Reply-To: <CAGyVUB5QLV+HQMWT+0kDu1_H0uXHK7kTy35WqhXQaETZ5if5EQ@mail.gmail.com>

```
On September 10, 2025 7:29 PM, ynckz wrote:
>I have a request for you. Could you please add private branches? This is a really
>useful thing.
>Imagine that you want to publish your project as open source, but you need to hide
>the .env file in a separate repository. It's easier to do everything in one repository,
>but in a different branch. Maybe there is another way, and I'm just dumb as fuck,
>but here's another example:
>Say you don't want to release a new feature yet. To do so, create a private branch,
>make the feature there, then merge it into the main branch.
>
>Maybe I'm a dumb ass, and don't need to ask this of you, but GitLab, etc., anyway,
>I'd appreciate it if you could add this feature.

Put your private content into a submodule and set the visibility of that submodule
to private in GitLab. Your *.env files go in there and will not get shared.

Once you have this working, please try to use polite language instead of what is
In your message. Thanks.


```

## brian m. carlson, 2025-09-11 00:00

Subject: Re: Git private branch Feature Suggestion
Message-ID: <aMIRO83CyG_qtKez@fruit.crustytoothpaste.net>
URL: https://gitlist.dev/e/aMIRO83CyG_qtKez%40fruit.crustytoothpaste.net
In-Reply-To: <CAGyVUB5QLV+HQMWT+0kDu1_H0uXHK7kTy35WqhXQaETZ5if5EQ@mail.gmail.com>

```
On 2025-09-10 at 23:28:54, ynckz wrote:
> Hi Git developers,
> 
> I have a request for you. Could you please add private branches? This
> is a really useful thing.
> Imagine that you want to publish your project as open source, but you
> need to hide the .env file in a separate repository. It's easier to do
> everything in one repository, but in a different branch. Maybe there
> is another way, and I'm just dumb as fuck, but here's another example:
> Say you don't want to release a new feature yet. To do so, create a
> private branch, make the feature there, then merge it into the main
> branch.

The reason we haven't added this is that it isn't secure.  Git has a
feature called namespaces, which basically implements the feature you
want.  There are different namespaces and references can be stored in
any one of them.

Here's what the gitnamespaces(5) manual page says about this:

    The fetch and push protocols are not designed to prevent one side
    from stealing data from the other repository that was not intended
    to be shared. If you have private data that you need to protect from
    a malicious peer, your best option is to store it in another
    repository. This applies to both clients and servers. In particular,
    namespaces on a server are not effective for read access control;
    you should only grant read access to a namespace to clients that you
    would trust with read access to the entire repository.

It then goes on to explain the kinds of approaches that can be used to
exploit this, but basically, if an attacker can find an object ID that
it thinks the server has, it can acquire information about that object.

Now, you might say, well, the object ID is private.  But it's very
common to leak those in issues, build logs, or as part of a version
identified in a build, so in general we can't base security on that.
Cryptography tells us that cryptographic hashes of general data are not
secrets, so we cannot rely on them for access control.

It could be possible to allow this _if_ Git had some way to know that
the client was only allowed to access certain refs _and_ Git were
configured to only allow access to objects that were reachable from
those refs.  However, Git doesn't have that information and that's in
general expensive to determine, so it would make things like partial
clone perform really terribly.  It would also require a lot of changes
to Git's internals and security model, and nobody has so far volunteered
to do that.

I will note that in general, secrets should never be checked into a
repository.  It's too easy to accidentally expose a repository, and when
that happens, you leak every secret in the entire history, and then
rotating them all is a colossal hassle.  (I know, I've had to do it.) If
you use a secret store, which is a security best practice, then this
doesn't happen.
-- 
brian m. carlson (they/them)
Toronto, Ontario, CA

```

## Henrique Soares, 2025-09-11 00:13

Subject: Re: Git private branch Feature Suggestion
Message-ID: <aMIUJJTUegO3Nzcm@localhost>
URL: https://gitlist.dev/e/aMIUJJTUegO3Nzcm%40localhost
In-Reply-To: <CAGyVUB5QLV+HQMWT+0kDu1_H0uXHK7kTy35WqhXQaETZ5if5EQ@mail.gmail.com>

```
On Thu, Sep 11, 2025 at 02:28:54AM +0300, ynckz wrote:
> I have a request for you. Could you please add private branches? This
> is a really useful thing.

Any branch created locally is private by default.
Just don't push it to the remote origin and nobody will have access to it.

> Imagine that you want to publish your project as open source, but you
> need to hide the .env file in a separate repository. It's easier to do
> everything in one repository, but in a different branch. Maybe there
> is another way, and I'm just dumb as fuck, but here's another example:

If you need to share the .env file to few people, but not to everyone,
then use a submodule.

-- Henrique

```

## Kristoffer Haugsbakk, 2025-09-11 08:15

Subject: Re: Git private branch Feature Suggestion
Message-ID: <fccd1ea3-c57d-4c41-a31b-f0563848416a@app.fastmail.com>
URL: https://gitlist.dev/e/fccd1ea3-c57d-4c41-a31b-f0563848416a%40app.fastmail.com
In-Reply-To: <CAGyVUB5QLV+HQMWT+0kDu1_H0uXHK7kTy35WqhXQaETZ5if5EQ@mail.gmail.com>

```
On Thu, Sep 11, 2025, at 01:28, ynckz wrote:
> Hi Git developers,
>
> I have a request for you. Could you please add private branches? This
> is a really useful thing.
> Imagine that you want to publish your project as open source, but you
> need to hide the .env file in a separate repository. It's easier to do
> everything in one repository, but in a different branch. Maybe there
> is another way, and I'm just dumb as fuck, but here's another example:
> Say you don't want to release a new feature yet. To do so, create a
> private branch, make the feature there, then merge it into the main
> branch.
>
> Maybe I'm a dumb ass, and don't need to ask this of you, but GitLab,
> etc., anyway, I'd appreciate it if you could add this feature.

I use a sibling repository `.git-mine` with files that don’t
overlap with those from `.git`.  This way I can have two “working trees”
checked out.

-- 
Kristoffer Haugsbakk

```
