2

I am trying to transfer a local git repository to a web server. I followed the approach here: Git: move existing repository from PC to server, clone from server

First I initialized an empty repository on my local machine, and added two files and did a commit. Then on the server I created a folder /www/git, and changed to that directory and did

git init --shared --bare

Then on the local machine I run

git remote add server user@server.com:/www/git

Then I did

git push server master

which gave output like:

Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 2.13 KiB, done.
Total 4 (delta 0), reused 0 (delta 0)
To user@server.com:/www/git
 * [new branch]      master -> master

However on the server, I cannot see any of the two files I added on local machine. If I do ls in /www/git I get:

HEAD  branches  config  description  hooks  info  objects  refs

but none of these are none of these files and directories are the one I pushed from my local machine.

Community
  • 1
  • 1
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174

1 Answers1

6

That's the point of a bare repository. It has no working directory, and no branch checked out. It's just the .git directory. It's meant to facilitate pushing and pulling, but not working with the files themselves.

If you want to actually work with the files on the server, you should checkout a non-bare copy of the repo somewhere else on the server. Then your client and server can continue to share code by pushing/pulling from the bare repo.

user229044
  • 232,980
  • 40
  • 330
  • 338
  • Thanks! But where are actually my files located now on the server? – Håkon Hægland Jul 02 '14 at 21:10
  • And why do I need two repos on the server? – Håkon Hægland Jul 02 '14 at 21:11
  • As I said, you've created a bare repository, and it has no working directory. Your files aren't anywhere where you can work with them, the commits and their associated objects are stored inside your bare repo. If you want to work with the files, you need to clone the bare repository to make a *non* bare repository, where you will see your files. – user229044 Jul 02 '14 at 21:14
  • I *suggest* using two repos, because you shouldn't be pushing to a non-bare repository. You only push to bare repos because you know that somebody isn't doing work there. If you want to use only two non-bare repositories, both repositories should be pulling from each other, but neither should be pushing. – user229044 Jul 02 '14 at 21:16
  • Ok, thanks meagar.. this makes it clear to me.. but I think I can be *sure* nobody is working with the files on the server. – Håkon Hægland Jul 02 '14 at 21:20