<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">

<sect2 lang="en" id="gitnamespaces(7)">
    <title>gitnamespaces(7)</title>
    <date>2024-07-02</date>
<revhistory><revision><date>2024-07-02</date></revision></revhistory>
<indexterm>
<primary>gitnamespaces(7)</primary>
</indexterm>
<simplesect id="gitnamespaces(7)__name">
<title>NAME</title>
<simpara>gitnamespaces - Git namespaces</simpara>
</simplesect>
<simplesect id="gitnamespaces(7)__synopsis">
<title>SYNOPSIS</title>
<blockquote>
<literallayout>GIT_NAMESPACE=&lt;namespace&gt; <emphasis>git upload-pack</emphasis>
GIT_NAMESPACE=&lt;namespace&gt; <emphasis>git receive-pack</emphasis></literallayout>
</blockquote>
</simplesect>
<simplesect id="gitnamespaces(7)__description">
<title>DESCRIPTION</title>
<simpara>Git supports dividing the refs of a single repository into multiple
namespaces, each of which has its own branches, tags, and HEAD.  Git can
expose each namespace as an independent repository to pull from and push
to, while sharing the object store, and exposing all the refs to
operations such as <xref linkend="git-gc(1)" />.</simpara>
<simpara>Storing multiple repositories as namespaces of a single repository
avoids storing duplicate copies of the same objects, such as when
storing multiple branches of the same source.  The alternates mechanism
provides similar support for avoiding duplicates, but alternates do not
prevent duplication between new objects added to the repositories
without ongoing maintenance, while namespaces do.</simpara>
<simpara>To specify a namespace, set the <emphasis>GIT_NAMESPACE</emphasis> environment variable to
the namespace.  For each ref namespace, Git stores the corresponding
refs in a directory under <emphasis>refs/namespaces/</emphasis>.  For example,
<emphasis>GIT_NAMESPACE=foo</emphasis> will store refs under <emphasis>refs/namespaces/foo/</emphasis>.  You
can also specify namespaces via the <emphasis>--namespace</emphasis> option to
<xref linkend="git(1)" />.</simpara>
<simpara>Note that namespaces which include a <emphasis>/</emphasis> will expand to a hierarchy of
namespaces; for example, <emphasis>GIT_NAMESPACE=foo/bar</emphasis> will store refs under
<emphasis>refs/namespaces/foo/refs/namespaces/bar/</emphasis>.  This makes paths in
<emphasis>GIT_NAMESPACE</emphasis> behave hierarchically, so that cloning with
<emphasis>GIT_NAMESPACE=foo/bar</emphasis> produces the same result as cloning with
<emphasis>GIT_NAMESPACE=foo</emphasis> and cloning from that repo with <emphasis>GIT_NAMESPACE=bar</emphasis>.  It
also avoids ambiguity with strange namespace paths such as <emphasis>foo/refs/heads/</emphasis>,
which could otherwise generate directory/file conflicts within the <emphasis>refs</emphasis>
directory.</simpara>
<simpara><xref linkend="git-upload-pack(1)" /> and <xref linkend="git-receive-pack(1)" /> rewrite the
names of refs as specified by <emphasis>GIT_NAMESPACE</emphasis>.  git-upload-pack and
git-receive-pack will ignore all references outside the specified
namespace.</simpara>
<simpara>The smart HTTP server, <xref linkend="git-http-backend(1)" />, will pass
GIT_NAMESPACE through to the backend programs; see
<xref linkend="git-http-backend(1)" /> for sample configuration to expose
repository namespaces as repositories.</simpara>
<simpara>For a simple local test, you can use <xref linkend="git-remote-ext(1)" />:</simpara>
<screen>git clone ext::'git --namespace=foo %s /tmp/prefixed.git'</screen>
</simplesect>
<simplesect id="gitnamespaces(7)__security">
<title>SECURITY</title>
<simpara>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.</simpara>
<simpara>The known attack vectors are as follows:</simpara>
<orderedlist numeration="arabic">
<listitem>
<simpara>
The victim sends "have" lines advertising the IDs of objects it has that
  are not explicitly intended to be shared but can be used to optimize the
  transfer if the peer also has them. The attacker chooses an object ID X
  to steal and sends a ref to X, but isn't required to send the content of
  X because the victim already has it. Now the victim believes that the
  attacker has X, and it sends the content of X back to the attacker
  later. (This attack is most straightforward for a client to perform on a
  server, by creating a ref to X in the namespace the client has access
  to and then fetching it. The most likely way for a server to perform it
  on a client is to "merge" X into a public branch and hope that the user
  does additional work on this branch and pushes it back to the server
  without noticing the merge.)
</simpara>
</listitem>
<listitem>
<simpara>
As in #1, the attacker chooses an object ID X to steal. The victim sends
  an object Y that the attacker already has, and the attacker falsely
  claims to have X and not Y, so the victim sends Y as a delta against X.
  The delta reveals regions of X that are similar to Y to the attacker.
</simpara>
</listitem>
</orderedlist>
</simplesect>
<simplesect id="gitnamespaces(7)__git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
</simplesect>
</sect2>
