summaryrefslogtreecommitdiffstats
path: root/man5/gitrepository-layout.5
blob: 235e5cd112c3c40d1654e766600184f8fb216b75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
'\" t
.\"     Title: gitrepository-layout
.\"    Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\"      Date: 2024-04-10
.\"    Manual: Git Manual
.\"    Source: Git 2.44.0.568.g436d4e5b14
.\"  Language: English
.\"
.TH "GITREPOSITORY\-LAYOUT" "5" "2024\-04\-10" "Git 2\&.44\&.0\&.568\&.g436d4e" "Git Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
gitrepository-layout \- Git Repository Layout
.SH "SYNOPSIS"
.sp
$GIT_DIR/*
.SH "DESCRIPTION"
.sp
A Git repository comes in two different flavours:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
a
\fB\&.git\fR
directory at the root of the working tree;
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
a
\fB<project>\&.git\fR
directory that is a
\fIbare\fR
repository (i\&.e\&. without its own working tree), that is typically used for exchanging histories with others by pushing into it and fetching from it\&.
.RE
.sp
\fBNote\fR: Also you can have a plain text file \fB\&.git\fR at the root of your working tree, containing \fBgitdir: <path>\fR to point at the real directory that has the repository\&. This mechanism is called a \fIgitfile\fR and is usually managed via the \fBgit submodule\fR and \fBgit worktree\fR commands\&. It is often used for a working tree of a submodule checkout, to allow you in the containing superproject to \fBgit checkout\fR a branch that does not have the submodule\&. The \fBcheckout\fR has to remove the entire submodule working tree, without losing the submodule repository\&.
.sp
These things may exist in a Git repository\&.
.PP
objects
.RS 4
Object store associated with this repository\&. Usually an object store is self sufficient (i\&.e\&. all the objects that are referred to by an object found in it are also found in it), but there are a few ways to violate it\&.
.sp
.RS 4
.ie n \{\
\h'-04' 1.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  1." 4.2
.\}
You could have an incomplete but locally usable repository by creating a shallow clone\&. See
\fBgit-clone\fR(1)\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 2.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  2." 4.2
.\}
You could be using the
\fBobjects/info/alternates\fR
or
\fB$GIT_ALTERNATE_OBJECT_DIRECTORIES\fR
mechanisms to
\fIborrow\fR
objects from other object stores\&. A repository with this kind of incomplete object store is not suitable to be published for use with dumb transports but otherwise is OK as long as
\fBobjects/info/alternates\fR
points at the object stores it borrows from\&.
.sp
This directory is ignored if $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/objects" will be used instead\&.
.RE
.RE
.PP
objects/[0\-9a\-f][0\-9a\-f]
.RS 4
A newly created object is stored in its own file\&. The objects are splayed over 256 subdirectories using the first two characters of the sha1 object name to keep the number of directory entries in
\fBobjects\fR
itself to a manageable number\&. Objects found here are often called
\fIunpacked\fR
(or
\fIloose\fR) objects\&.
.RE
.PP
objects/pack
.RS 4
Packs (files that store many objects in compressed form, along with index files to allow them to be randomly accessed) are found in this directory\&.
.RE
.PP
objects/info
.RS 4
Additional information about the object store is recorded in this directory\&.
.RE
.PP
objects/info/packs
.RS 4
This file is to help dumb transports discover what packs are available in this object store\&. Whenever a pack is added or removed,
\fBgit update\-server\-info\fR
should be run to keep this file up to date if the repository is published for dumb transports\&.
\fIgit repack\fR
does this by default\&.
.RE
.PP
objects/info/alternates
.RS 4
This file records paths to alternate object stores that this object store borrows objects from, one pathname per line\&. Note that not only native Git tools use it locally, but the HTTP fetcher also tries to use it remotely; this will usually work if you have relative paths (relative to the object database, not to the repository!) in your alternates file, but it will not work if you use absolute paths unless the absolute path in filesystem and web URL is the same\&. See also
\fBobjects/info/http\-alternates\fR\&.
.RE
.PP
objects/info/http\-alternates
.RS 4
This file records URLs to alternate object stores that this object store borrows objects from, to be used when the repository is fetched over HTTP\&.
.RE
.PP
refs
.RS 4
References are stored in subdirectories of this directory\&. The
\fIgit prune\fR
command knows to preserve objects reachable from refs found in this directory and its subdirectories\&. This directory is ignored (except refs/bisect, refs/rewritten and refs/worktree) if $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/refs" will be used instead\&.
.RE
.PP
refs/heads/\fBname\fR
.RS 4
records tip\-of\-the\-tree commit objects of branch
\fBname\fR
.RE
.PP
refs/tags/\fBname\fR
.RS 4
records any object name (not necessarily a commit object, or a tag object that points at a commit object)\&.
.RE
.PP
refs/remotes/\fBname\fR
.RS 4
records tip\-of\-the\-tree commit objects of branches copied from a remote repository\&.
.RE
.PP
refs/replace/\fB<obj\-sha1>\fR
.RS 4
records the SHA\-1 of the object that replaces
\fB<obj\-sha1>\fR\&. This is similar to info/grafts and is internally used and maintained by
\fBgit-replace\fR(1)\&. Such refs can be exchanged between repositories while grafts are not\&.
.RE
.PP
packed\-refs
.RS 4
records the same information as refs/heads/, refs/tags/, and friends record in a more efficient way\&. See
\fBgit-pack-refs\fR(1)\&. This file is ignored if $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/packed\-refs" will be used instead\&.
.RE
.PP
HEAD
.RS 4
A symref (see glossary) to the
\fBrefs/heads/\fR
namespace describing the currently active branch\&. It does not mean much if the repository is not associated with any working tree (i\&.e\&. a
\fIbare\fR
repository), but a valid Git repository
\fBmust\fR
have the HEAD file; some porcelains may use it to guess the designated "default" branch of the repository (usually
\fImaster\fR)\&. It is legal if the named branch
\fIname\fR
does not (yet) exist\&. In some legacy setups, it is a symbolic link instead of a symref that points at the current branch\&.
.sp
HEAD can also record a specific commit directly, instead of being a symref to point at the current branch\&. Such a state is often called
\fIdetached HEAD\&.\fR
See
\fBgit-checkout\fR(1)
for details\&.
.RE
.PP
config
.RS 4
Repository specific configuration file\&. This file is ignored if $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/config" will be used instead\&.
.RE
.PP
config\&.worktree
.RS 4
Working directory specific configuration file for the main working directory in multiple working directory setup (see
\fBgit-worktree\fR(1))\&.
.RE
.PP
branches
.RS 4
A slightly deprecated way to store shorthands to be used to specify a URL to
\fIgit fetch\fR,
\fIgit pull\fR
and
\fIgit push\fR\&. A file can be stored as
\fBbranches/<name>\fR
and then
\fIname\fR
can be given to these commands in place of
\fIrepository\fR
argument\&. See the REMOTES section in
\fBgit-fetch\fR(1)
for details\&. This mechanism is legacy and not likely to be found in modern repositories\&. This directory is ignored if $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/branches" will be used instead\&.
.RE
.PP
hooks
.RS 4
Hooks are customization scripts used by various Git commands\&. A handful of sample hooks are installed when
\fIgit init\fR
is run, but all of them are disabled by default\&. To enable, the
\fB\&.sample\fR
suffix has to be removed from the filename by renaming\&. Read
\fBgithooks\fR(5)
for more details about each hook\&. This directory is ignored if $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/hooks" will be used instead\&.
.RE
.PP
common
.RS 4
When multiple working trees are used, most of files in $GIT_DIR are per\-worktree with a few known exceptions\&. All files under
\fIcommon\fR
however will be shared between all working trees\&.
.RE
.PP
index
.RS 4
The current index file for the repository\&. It is usually not found in a bare repository\&.
.RE
.PP
sharedindex\&.<SHA\-1>
.RS 4
The shared index part, to be referenced by $GIT_DIR/index and other temporary index files\&. Only valid in split index mode\&.
.RE
.PP
info
.RS 4
Additional information about the repository is recorded in this directory\&. This directory is ignored if $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/info" will be used instead\&.
.RE
.PP
info/refs
.RS 4
This file helps dumb transports discover what refs are available in this repository\&. If the repository is published for dumb transports, this file should be regenerated by
\fIgit update\-server\-info\fR
every time a tag or branch is created or modified\&. This is normally done from the
\fBhooks/update\fR
hook, which is run by the
\fIgit\-receive\-pack\fR
command when you
\fIgit push\fR
into the repository\&.
.RE
.PP
info/grafts
.RS 4
This file records fake commit ancestry information, to pretend the set of parents a commit has is different from how the commit was actually created\&. One record per line describes a commit and its fake parents by listing their 40\-byte hexadecimal object names separated by a space and terminated by a newline\&.
.sp
Note that the grafts mechanism is outdated and can lead to problems transferring objects between repositories; see
\fBgit-replace\fR(1)
for a more flexible and robust system to do the same thing\&.
.RE
.PP
info/exclude
.RS 4
This file, by convention among Porcelains, stores the exclude pattern list\&.
\fB\&.gitignore\fR
is the per\-directory ignore file\&.
\fIgit status\fR,
\fIgit add\fR,
\fIgit rm\fR
and
\fIgit clean\fR
look at it but the core Git commands do not look at it\&. See also:
\fBgitignore\fR(5)\&.
.RE
.PP
info/attributes
.RS 4
Defines which attributes to assign to a path, similar to per\-directory
\fB\&.gitattributes\fR
files\&. See also:
\fBgitattributes\fR(5)\&.
.RE
.PP
info/sparse\-checkout
.RS 4
This file stores sparse checkout patterns\&. See also:
\fBgit-read-tree\fR(1)\&.
.RE
.PP
remotes
.RS 4
Stores shorthands for URL and default refnames for use when interacting with remote repositories via
\fIgit fetch\fR,
\fIgit pull\fR
and
\fIgit push\fR
commands\&. See the REMOTES section in
\fBgit-fetch\fR(1)
for details\&. This mechanism is legacy and not likely to be found in modern repositories\&. This directory is ignored if $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/remotes" will be used instead\&.
.RE
.PP
logs
.RS 4
Records of changes made to refs are stored in this directory\&. See
\fBgit-update-ref\fR(1)
for more information\&. This directory is ignored (except logs/HEAD) if $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/logs" will be used instead\&.
.RE
.PP
logs/refs/heads/\fBname\fR
.RS 4
Records all changes made to the branch tip named
\fBname\fR\&.
.RE
.PP
logs/refs/tags/\fBname\fR
.RS 4
Records all changes made to the tag named
\fBname\fR\&.
.RE
.PP
shallow
.RS 4
This is similar to
\fBinfo/grafts\fR
but is internally used and maintained by shallow clone mechanism\&. See
\fB\-\-depth\fR
option to
\fBgit-clone\fR(1)
and
\fBgit-fetch\fR(1)\&. This file is ignored if $GIT_COMMON_DIR is set and "$GIT_COMMON_DIR/shallow" will be used instead\&.
.RE
.PP
commondir
.RS 4
If this file exists, $GIT_COMMON_DIR (see
\fBgit\fR(1)) will be set to the path specified in this file if it is not explicitly set\&. If the specified path is relative, it is relative to $GIT_DIR\&. The repository with commondir is incomplete without the repository pointed by "commondir"\&.
.RE
.PP
modules
.RS 4
Contains the git\-repositories of the submodules\&.
.RE
.PP
worktrees
.RS 4
Contains administrative data for linked working trees\&. Each subdirectory contains the working tree\-related part of a linked working tree\&. This directory is ignored if $GIT_COMMON_DIR is set, in which case "$GIT_COMMON_DIR/worktrees" will be used instead\&.
.RE
.PP
worktrees/<id>/gitdir
.RS 4
A text file containing the absolute path back to the \&.git file that points to here\&. This is used to check if the linked repository has been manually removed and there is no need to keep this directory any more\&. The mtime of this file should be updated every time the linked repository is accessed\&.
.RE
.PP
worktrees/<id>/locked
.RS 4
If this file exists, the linked working tree may be on a portable device and not available\&. The presence of this file prevents
\fBworktrees/<id>\fR
from being pruned either automatically or manually by
\fBgit worktree prune\fR\&. The file may contain a string explaining why the repository is locked\&.
.RE
.PP
worktrees/<id>/config\&.worktree
.RS 4
Working directory specific configuration file\&.
.RE
.SH "GIT REPOSITORY FORMAT VERSIONS"
.sp
Every git repository is marked with a numeric version in the \fBcore\&.repositoryformatversion\fR key of its \fBconfig\fR file\&. This version specifies the rules for operating on the on\-disk repository data\&. An implementation of git which does not understand a particular version advertised by an on\-disk repository MUST NOT operate on that repository; doing so risks not only producing wrong results, but actually losing data\&.
.sp
Because of this rule, version bumps should be kept to an absolute minimum\&. Instead, we generally prefer these strategies:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
bumping format version numbers of individual data files (e\&.g\&., index, packfiles, etc)\&. This restricts the incompatibilities only to those files\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
introducing new data that gracefully degrades when used by older clients (e\&.g\&., pack bitmap files are ignored by older clients, which simply do not take advantage of the optimization they provide)\&.
.RE
.sp
A whole\-repository format version bump should only be part of a change that cannot be independently versioned\&. For instance, if one were to change the reachability rules for objects, or the rules for locking refs, that would require a bump of the repository format version\&.
.sp
Note that this applies only to accessing the repository\(cqs disk contents directly\&. An older client which understands only format \fB0\fR may still connect via \fBgit://\fR to a repository using format \fB1\fR, as long as the server process understands format \fB1\fR\&.
.sp
The preferred strategy for rolling out a version bump (whether whole repository or for a single file) is to teach git to read the new format, and allow writing the new format with a config switch or command line option (for experimentation or for those who do not care about backwards compatibility with older gits)\&. Then after a long period to allow the reading capability to become common, we may switch to writing the new format by default\&.
.sp
The currently defined format versions are:
.SS "Version \fB0\fR"
.sp
This is the format defined by the initial version of git, including but not limited to the format of the repository directory, the repository configuration file, and the object and ref storage\&. Specifying the complete behavior of git is beyond the scope of this document\&.
.SS "Version \fB1\fR"
.sp
This format is identical to version \fB0\fR, with the following exceptions:
.sp
.RS 4
.ie n \{\
\h'-04' 1.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  1." 4.2
.\}
When reading the
\fBcore\&.repositoryformatversion\fR
variable, a git implementation which supports version 1 MUST also read any configuration keys found in the
\fBextensions\fR
section of the configuration file\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04' 2.\h'+01'\c
.\}
.el \{\
.sp -1
.IP "  2." 4.2
.\}
If a version\-1 repository specifies any
\fBextensions\&.*\fR
keys that the running git has not implemented, the operation MUST NOT proceed\&. Similarly, if the value of any known key is not understood by the implementation, the operation MUST NOT proceed\&.
.RE
.sp
Note that if no extensions are specified in the config file, then \fBcore\&.repositoryformatversion\fR SHOULD be set to \fB0\fR (setting it to \fB1\fR provides no benefit, and makes the repository incompatible with older implementations of git)\&.
.sp
This document will serve as the master list for extensions\&. Any implementation wishing to define a new extension should make a note of it here, in order to claim the name\&.
.sp
The defined extensions are:
.sp
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
\fBnoop\fR
.RS 4
.sp
This extension does not change git\(cqs behavior at all\&. It is useful only for testing format\-1 compatibility\&.
.RE
.sp
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
\fBpreciousObjects\fR
.RS 4
.sp
When the config key \fBextensions\&.preciousObjects\fR is set to \fBtrue\fR, objects in the repository MUST NOT be deleted (e\&.g\&., by \fBgit\-prune\fR or \fBgit repack \-d\fR)\&.
.RE
.sp
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
\fBpartialClone\fR
.RS 4
.sp
When the config key \fBextensions\&.partialClone\fR is set, it indicates that the repo was created with a partial clone (or later performed a partial fetch) and that the remote may have omitted sending certain unwanted objects\&. Such a remote is called a "promisor remote" and it promises that all such omitted objects can be fetched from it in the future\&.
.sp
The value of this key is the name of the promisor remote\&.
.RE
.sp
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
\fBworktreeConfig\fR
.RS 4
.sp
If set, by default "git config" reads from both "config" and "config\&.worktree" files from GIT_DIR in that order\&. In multiple working directory mode, "config" file is shared while "config\&.worktree" is per\-working directory (i\&.e\&., it\(cqs in GIT_COMMON_DIR/worktrees/<id>/config\&.worktree)
.RE
.sp
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
\fBrefStorage\fR
.RS 4
.sp
Specifies the file format for the ref database\&. The valid values are \fBfiles\fR (loose references with a packed\-refs file) and \fBreftable\fR (see Documentation/technical/reftable\&.txt)\&.
.RE
.SH "SEE ALSO"
.sp
\fBgit-init\fR(1), \fBgit-clone\fR(1), \fBgit-fetch\fR(1), \fBgit-pack-refs\fR(1), \fBgit-gc\fR(1), \fBgit-checkout\fR(1), \fBgitglossary\fR(7), \m[blue]\fBThe Git User\(cqs Manual\fR\m[]\&\s-2\u[1]\d\s+2
.SH "GIT"
.sp
Part of the \fBgit\fR(1) suite
.SH "NOTES"
.IP " 1." 4
The Git User\(cqs Manual
.RS 4
\%git-htmldocs/user-manual.html
.RE