86

I just ran the following commands on my Ruby on Rails project:

git init
git add .
git commit -a -m 'Initial'

Where does Git actually store this repository? (It's on my local machine, but where?)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Yuval Karmi
  • 26,277
  • 39
  • 124
  • 175

10 Answers10

111

It will create your repository in the .git folder in the current directory.

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • Hi there, I have the same problem. My disk ran out of space before the git could finish cloning and now I don't know where to delete the old clone. I was in ~ directory when running GIT but there is no .git folder in ~ or /. What should I do? Thanks you. – Max Mar 18 '13 at 04:28
  • 1
    I don't know why there would be no .git directory. Did you try `ls -ld .git` when in ~? – Matthew Flaschen Mar 18 '13 at 19:30
  • Hi there, thank you for your answer. I still haven't found the clone yet, but the second git succeeded and the .git folder is store in `~/common/.git` (`common` is the name of the package). I reckon GIT stores unfinished jobs in a temp folder and upon success it transfers back to current directory. I just hope it has deleted nonsuccessive downloads. – Max Mar 18 '13 at 19:46
  • Sorry, I misread your comment (I thought you were talking about initializing a clean repo). Yes, if you clone, it will create a new directory. – Matthew Flaschen Mar 18 '13 at 20:23
  • 13
    It's good to mention that it's a hidden directory, just in case someone doesn't see it. – B.K. Jul 26 '14 at 22:31
  • 1
    @B.K. pointed this out, affects Windows, the folder is hidden. Just so everyone knows how they can see it (Windows 7): F10 -> Tools -> Folder Options -> View -> Show hidden files and folders (in the radio buttons in advanced settings) – RebelFist Jan 20 '16 at 02:49
  • Man, visual studio code's git checked in my stuffs somewhere, I thought in the internet :(. Now I know where it is. Thank you :) – Relativity Nov 29 '16 at 23:35
  • it is stored in the actual folder right? How do you see tracks of your commits? does it have a GUI? – Grizzly Bear Jul 13 '20 at 09:21
34

To be a bit more complete, Git works with:

  • the working tree (the root of which being where you made a git init)
  • "path to the Git repository" (where there is a .git, which will store the revisions of all your files)

GIT_DIR is an environment variable, which can be an absolute path or relative path to current working directory.

If it is not defined, the "path to the git repository" is by default at the root directory of your working tree (again, where you made a git init).

You can actually execute any Git command from anywhere from your disk, provided you specify the working tree path and the Git repository path:

git command --git-dir=<path> --work-tree=<path>

But if you execute them in one of the subdirectories of a Git repository (with no GIT-DIR or working tree path specified), Git will simply look in the current and parent directories until it find a .git, assume this it also the root directory of your working tree, and use that .git as the only container for all the revisions of your files.

Note: .git is also hidden in Windows (msysgit).
You would have to do a dir /AH to see it.
git 2.9 (June 2016) allows to configure that.


Note that Git 2.18 (Q2 2018) is starting the process to evolve how Git is storing objects, by refactoring the internal global data structure to make it possible to open multiple repositories, work with and then close them.

See commit 4a7c05f, commit 1fea63e (23 Mar 2018) by Jonathan Nieder (artagnon).
See commit bd27f50, commit ec7283e, commit d2607fa, commit a68377b, commit e977fc7, commit e35454f, commit 332295d, commit 2ba0bfd, commit fbe33e2, commit cf78ae4, commit 13068bf, commit 77f012e, commit 0b20903, commit 93d8d1e, commit ca5e6d2, commit cfc62fc, commit 13313fc, commit 9a00580 (23 Mar 2018) by Stefan Beller (stefanbeller).
(Merged by Junio C Hamano -- gitster -- in commit cf0b179, 11 Apr 2018)

repository: introduce raw object store field

The raw object store field will contain any objects needed for access to objects in a given repository.

This patch introduces the raw object store and populates it with the objectdir, which used to be part of the repository struct.

As the struct gains members, we'll also populate the function to clear the memory for these members.

In a later step, we'll introduce a struct object_parser, that will complement the object parsing in a repository struct:

  • The raw object parser is the layer that will provide access to raw object content,
  • while the higher level object parser code will parse raw objects and keeps track of parenthood and other object relationships using 'struct object'.

    For now only add the lower level to the repository struct.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Sure, but where are the versions of the files of your code? If I swap branches, how does git grab that branch information? Seems to be more complete answers (perhaps more accurately answering "where does git store _changes_" than the OP's ?, perhaps) [here](http://superuser.com/a/159338/114388) and [here](http://stackoverflow.com/questions/5176225/are-gits-pack-files-deltas-rather-than-snapshots). Not sure that's worth an edit, though. – ruffin Mar 08 '12 at 14:26
  • @ruffin: good links, but as you noticed, not *exactly* the OP's question. – VonC Mar 08 '12 at 14:34
19

If you are on an English Windows machine, Git's default storage path will be C:\Documents and Settings\< current_user>\, because on Windows the default Git local settings resides at C:\Documents and Settings\< current_user>\.git and so Git creates a separate folder for each repo/clone at C:\Documents and Settings\< current_user>\ and there are all the directories of cloned project.

For example, if you install Symfony 2 with

git clone git://github.com/symfony/symfony.git

the Symfony directory and file will be at

C:\Documents and Settings\< current_user>\symfony\
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Vishal Bandre
  • 359
  • 3
  • 3
  • 2
    You are talking about the `HOME` directory of git bash. If you change directory, of course the cloned repositories get created in the directory you are calling `git clone` from. What actually answers the question is that git stores the files in a folder called `.git` inside the repository, wherever you have chosen to clone it. – Shahbaz Jun 11 '13 at 12:54
  • 1
    on `Windows 8.1` : `C:\Users\user_name\.project_name` or call from `Run` `...\.project_name`. – Vy Do Oct 09 '15 at 16:03
9

In the root directory of the project there is a hidden .git directory that contains configuration, the repository etc.

Brenton Alker
  • 8,947
  • 3
  • 36
  • 37
4

I'm on Windows and found my location by right clicking the Git Bash program in my Start menu and selecting Properties. The Shortcut tab shows the "Start in:" value. For me, it was %HOMEDRIVE%%HOMEPATH%, so I opened a CMD prompt and typed echo %HOMEDRIVE%%HOMEPATH% to see the actual location.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
user2271109
  • 104
  • 2
3

I also couldn't find my git repository. I am using Windows 8 and created my repository (by mistake) under C:\Program Files (x86)\Git. I could see the repository folder in bash but not in cmd or Windows Explorer.

Then I remembered about Windows's "Virtual Store" feature. My repository folder was actually created under C:\Users\<username>\AppData\Local\VirtualStore\Program Files (x86)\Git\<myrepo> and in there was my .git folder!

bouvierr
  • 3,563
  • 3
  • 27
  • 32
  • 1
    How to you make it work 'correctly' and put folder where you want? I'm having other/similar issues, but all related to virtualstore I think. – Terry Dec 02 '14 at 16:39
  • On Windows Vista and later, a non-admin user is not allowed to create a file in `Program Files`, which is common to all users. Windows will instead create the file in the user's `VirtualStore` folder. The simplest solution is to avoid creating files in restricted folders and instead create them somewhere like in `Documents`. – bouvierr Apr 11 '15 at 15:01
3

In a .git directory in the root of the project. Unlike some other version control systems, notably CVS, there are no additional directories in any of the subdirectories.

Peter Tillemans
  • 34,983
  • 11
  • 83
  • 114
0

If you are looking for where the project folder was created. I noticed when I typed in the git bash.

$ git init projectName

it will tell me, where the project folder is for that project.

0

For me when I run git clone, Git will store the cloned package in the directory that I am running the command from.

- I use windows.

for example :

C:\Users\user>git clone https://github.com/broosaction/aria

will create a folder:

 C:\Users\user\aria
0

it may created but it still hidden to show it go to your file explorer setting go to (view) then check the box at hidden item and go to your repository and refresh it and the

Aymn
  • 1