78

If I make an analogy with the hosting of a web server, I would say that git's data should be in /var/git, so my git repository would be in /var/git/myrepo

Q: Is that the right guess ?

1
  • 1
    The correct answer is /srv/git, and official git's manual uses this path as well: link.
    – aderchox
    Nov 15, 2021 at 7:34

11 Answers 11

36

There is no right or wrong answer here, except the one dictated by your own personal religion and the contents of the hier(7) manpage on your system.

typical Linux hier manpage ; typical BSD hier manpage)

/var/git/* seems reasonable to me personally. That's where I keep mine.

4
  • 3
    Similarly, in Arch Linux apache's folder is /srv/http (instead of /var/www like some other distros) so I put my git stuff in /srv/git.
    – trusktr
    Jan 30, 2014 at 8:14
  • 1
    Somewhere under /var/ seems reasonable, but see also Denis R's answer below: serverfault.com/a/433584/45819 - he puts it into /var/lib/git with good reasons
    – mit
    Jun 8, 2018 at 8:18
  • Wrong answer! The correct answer would have been something along the lines of "anywhere under /home/{user}"
    – anton1980
    Sep 28, 2020 at 0:48
  • @anton1980: and who would be "correct" user in this case? Remember this is a git server
    – MestreLion
    Nov 25, 2021 at 15:41
37

Place it in a directory (or shared filesystem) under /srv. This is what it's for.

The /srv directory is intended for site-specific data served by the system. From the standard:

This main purpose of specifying this is so that users may find the location of the data files for particular service, and so that services which require a single tree for readonly data, writable data and scripts (such as cgi scripts) can be reasonably placed. Data that is only of interest to a specific user should go in that users' home directory.

The methodology used to name subdirectories of /srv is unspecified as there is currently no consensus on how this should be done. One method for structuring data under /srv is by protocol, eg. ftp, rsync, www, and cvs. On large systems it can be useful to structure /srv by administrative context, such as /srv/physics/www, /srv/compsci/cvs, etc. This setup will differ from host to host. Therefore, no program should rely on a specific subdirectory structure of /srv existing or data necessarily being stored in /srv. However /srv should always exist on FHS compliant systems and should be used as the default location for such data.

Distributions must take care not to remove locally placed files in these directories without administrator permission.


On an SELinux-enabled system, the default directory is /var/www/git, and repos should be in subdirectories thereof. Or, you can use, e.g. /srv/git and set the file context to be equivalent:

semanage fcontext -a -e /var/www/git /srv/git
4
  • Another wrong answer. The author said "my git repository". This is clearly his data, not relevant to any other users of the system. So, it should go somewhere under ~/
    – anton1980
    Sep 28, 2020 at 0:50
  • 3
    @anton1980 You seem to have misinterpreted the question. Sep 28, 2020 at 1:35
  • @anton1980 He clearly speaks about an analogy of "hosting a web server" so we are talking about git repos he is serving to the outside world. Why you think this "is clearly his data, not relevant to others", would be interesting. Also, please don't post the same comment under every answer ;)
    – m4110c
    Sep 9, 2021 at 3:18
  • "data files for particular service" --> this makes it clear, and the Git's official manual (link) uses this path as well. However, it's also worth mentioning that although using /var for this purpose is not right, it's a very common "wrong" and so probably safe. I'd personally stick to the /srv though, its name makes more sense to me. Also I don't agree with /var/lib/git as to me, it is a place that the git as a service itself might want to use.
    – aderchox
    Nov 15, 2021 at 7:32
7
/home/git/

This might seem a bit unconventional at first but it is very reasonable as this directory is made for you (with correct permissions) when you do sudo useradd git. You can just switch to the git user, cd and immediately run:

$ mkdir .ssh; chmod 700 .ssh
$ touch .ssh/authorized_keys; chmod 600 .ssh/authorized_keys

and put public keys of your peers into the just created authorized_keys file.

After you git init --bare your project, the "url" is then just...wait for it...

git@<server>:<project>
3
2

As voretaq7 said, there is no right or wrong answer on such a subject. However, if you want to follow of softs, it seems that database softs store their data in

/var/lib/soft

For example, for Postgresql 9.1 on debian the folder is

/var/lib/postgresql/9.1/

So I would personnaly choose

/var/lib/git
2

On my Arch Linux I have /srv/http for apache (which is system default) and I use it for my node.js http servers too. Similarly I decided to just put all git repositories in /srv/git.

I use GitLab, and /srv/git is the home folder for git in that case too.

Ultimately, it's up to you. I found that sticking to a format similar to other services in your distro is easy to remember.

1

It's entirely up to you. Optimally, though, you should put the git data dir on a separate partition or even disk to make system upgrades etc. easier and of course, you have to make sure that there is enough disk space available.

1

Technically, you can choose whereever you have permission but Git Project offers

/home/user/my_project

at its documentation.

0

If you use some frontend to git, just go with wherever the one packaged by your distribution wants to place them. Anything else is just creating needless incompatibilities.

2
  • 1/ I'm not using a frontend to git 2/ Git doens't come with a recomendation on where to place git repositories... any folder where you do git init is a git repository. Mar 1, 2013 at 21:45
  • 1/ By front end i would assume the git server serving the repos. 2/ any such server, even if only a HTTP server is used would have a default location. Of course we are talking about the location for hosting, when you work with the code the .git is mostly inside the project.
    – hultqvist
    Jan 30, 2014 at 17:23
0

First, regarding the suggestion to use /srv, you are under the assumption that all git repositories are used for websites. It may be true for you, but you could have a piece of software that is not a website.

Second, by storing your code repositories outside of the /var/www/html or /srv/html, you get two nice benefits. You can create symbolic links into your repo at any level, making it easier to hide your libraries. Also, if your repository's location changes at all, you don't have to modify your virtual host configurations. Instead you just adjust your symbolic links.

I was using /var/repo, but I think /var/git is better, and will be using that from now on.

0

When I am downloading git repos in order to maintain site configurations which I then deploy I store them in

/data/repos/$REPO_GROUP_OR_USER/$REPO_NAME

0

To add another option to the pool: as the linux kernel headers and DKMS kernel module sources are installed into /usr/src/ on debian, I've mounted a BTRFS volume under /usr/src/repos/ where all the git projects go... Now I just need to transfer that volume off the end of the slowest hard disk in my machine xD

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .