git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: how to reduce disk usage for large .git dirs?

From
RGRoger Gammans <roger@gammascience.co.uk>
Date
Nov 13, 2014, 12:02 UTC
Message-ID
<1415880149.4825.43.camel@knuth.computer-surgery.co.uk>
In-Reply-To
<20141113111444.GA15503@aepfle.de>
On Thu, 2014-11-13 at 12:14 +0100, Olaf Hering wrote:
Show 24 quoted lines
> How can I reduce the disk usage for multiple copies of the same repo?
> 
> Up to now I just made copies like this, but since .git alone is already
> 2GB it becomes expensive:
> 
>  # git clone git://host/repo.git repo-master
>  # cp -a repo-master repo-branchA
>  # cd repo-branchA
>  # git checkout -b branchA origin/branchA
>  # cd -
>  # cp -a repo-master repo-branchB
>  # cd repo-branchB
>  # git checkout -b branchB origin/branchB
>  # cd -
>  # cp -a repo-master repo-branchB-feature
>  # cd repo-branchB-feature
>  # git checkout -b branchB-feature origin/branchB
>  # cd -
> 
> 
> Since each .git is almost identical I wonder if there is a reliable way
> to "share" it. The "git clone" man page mentions --shared as a dangerous
> way to do things. It does not give an advice how to manage such cloned
> trees.
But you're not using clone you are using cp .
The clone man page also says this:-
      --local, -l
           When the repository to clone from is on a local machine, this flag bypasses the normal "Git aware" transport
           mechanism and clones the repository by making a copy of HEAD and everything under objects and refs directories. The
           files under .git/objects/ directory are hardlinked to save space when possible.
           If the repository is specified as a local path (e.g., /path/to/repo), this is the default, and --local is essentially
           a no-op. If the repository is specified as a URL, then this flag is ignored (and we never use the local
           optimizations). Specifying --no-local will override the default when /path/to/repo is given, using the regular Git
           transport instead.
Note the first sentence of the second paragraph.
 eg:
 # git clone git://host/repo.git repo-master
 # git clone repo-master repo-branchA
 # cd repo-branchA
 # git checkout -b branchA origin/branchA
 # cd -
 # git clone repo-master repo-branchB
 # cd repo-branchB
 # git checkout -b branchB origin/branchB
 # cd -
 # git clone repo-master repo-branchB-feature
 # cd repo-branchB-feature
 # git checkout -b branchB-feature origin/branchB
 # cd -

Should work better for you. And there is probably a way to do it less commands too.

-- 
Roger Gammans <roger@gammascience.co.uk>
Previous: Jakub NarębskiNext: Olaf Hering
Message 5 of 18 in “how to reduce disk usage for large .git dirs?”
  1. Olaf HeringNov 13, 2014
  2. Fredrik GustafssonNov 13, 2014
  3. Olaf HeringNov 13, 2014
  4. Jakub NarębskiNov 14, 2014
  5. Roger GammansNov 13, 2014
  6. Olaf HeringNov 13, 2014
  7. Duy NguyenNov 13, 2014
  8. Olaf HeringNov 13, 2014
  9. Fredrik GustafssonNov 13, 2014
  10. Johan HerlandNov 13, 2014
  11. Jeff KingNov 13, 2014
  12. Olaf HeringNov 14, 2014
  13. Fredrik GustafssonNov 14, 2014
  14. Olaf HeringNov 14, 2014
  15. Olaf HeringNov 14, 2014
  16. Olaf HeringNov 14, 2014
  17. Andreas SchwabNov 14, 2014
  18. Olaf HeringNov 25, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.