Git on Windows: Where are my files?

WARNING: I'M NEW TO GIT!!

I installed git on my local machine. I also installed it on a server on our network. On the server, I created C:\git to house my code and shared that directory. So, I did:

$cd C:\git
$git init --bare

I set up a new remote on my local machine to point to the shared directory of the "git server"

$git remote add shared "//shared/path/to/git/folder"
$cd C:\path\to\my\source\code
$git init
$git add -A
$git commit -m "initial push"
$git push shared master
$git checkout -b test
$git push shared test

So, now that I've done all that, when I go back to the server, I am expecting to see the server copies of my source code there, but I don't see it. Am I missing the entire point of git or am I doing something wrong?

Answers


Git stores your source as "binary large objects" (BLOBs, or just "objects" for short). A bare repository, like the one on your server, contains ONLY those BLOBs, not a "working tree", which is what your cloned repository has, which is why you can't see your files as normal on the server. They're there, uniquely named based on their content, in the objects directory. Try this experiment:

git init

echo "hello" > hello.txt

git add hello.txt

dir .git/objects

You'll see a subdirectory called 2a. Look inside that directory:

dir .git/objects/2a

You'll see a file called 93d00994fbd8c484f38b0423b7c42e87a55d48. The directory name (2a) along with the filename make up the SHA1 hash of the contents of the file hello.txt (the string "hello", that is).

Now if you type:

git cat-file -p 2a93d00994fbd8c484f38b0423b7c42e87a55d48

You'll see the contents of hello.txt! That's the object that'll be stored in the bare repository, which is why you don't just see the file hello.txt sitting there; it's been given a special name, compressed, and put in the objects directory.

As your repository grows, things get a little more complicated, because as the size of your content, and the number of your commits grow, Git starts packing similar files together; all of the information is still there, but it's further compressed for efficiency.

Another way you can reassure yourself that your files are indeed being stored on your server, you can create another clone (not a bare one!) and you'll have a working tree with all of your files in it.


You intialized bare repository. It does not have source code structure. It does not contain a "working tree" at all. Instead, it contains all the contents of the .git subdirectory right in the main directory itself.

So if you want a working copy on your server you have to clone your code from bare repo. Then pull latest commits to syncronize it.


Need Your Help

iOS - Perform selector from UIViewController from willEnterForeground

objective-c ios uitableview multitasking background-foreground

I have a -(void) method in my main UITableView class, which I use to refresh the data. It's somewhat complex, so I'm not going to post it here, but it is also called during viewWillAppear, so every...

ListBox HorizontalScrollbar doen't work WinForms

c# .net winforms listbox

I have a ListBox in winforms , C# application.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.