17

I'm trying to use git to deploy my local code in my remote server.

So here is what I've done in my local folder mywebsite/ :

git init
git add .
git commit -m "Initial commit"

Then, on my web server :

mkdir ~/public_html/myrepo.git
cd myrepo.git
git init --bare

Then, on my local folder mywebsite/ :

git remote add remote_mywebsite ssh://[email protected]:port/~/public_html/myrepo.git
git push remote_mywebsite master

which gave this result :

Counting objects: 89, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (74/74), done.
Writing objects: 100% (89/89), 61.94 KiB, done.
Total 89 (delta 2), reused 0 (delta 0)
To ssh://[email protected]:8943/~/public_html/myrepo.git
 * [new branch] master -> master
git pull remote_mywebsite

But when I log in to my web server, in the myrepo.git, I'm still having these files and folders

./
../
branches/
config
description
HEAD
hooks/
info/
objects/
refs/

and I don't retrieve the files and folders I have in my local mywebsite folder.

How could I retrieve my code in the remote myrepo.git folder ? Did I do something wrong ?

Thanks a lot for your help!

Dhirendra
7909 silver badges27 bronze badges
asked Mar 17, 2013 at 17:25
2
  • 1
    You don't have the files because you created a bare repository. A bare repository only contains the object database. To retrieve your files on the server, create a clone of the bare repository. Commented Mar 17, 2013 at 17:30
  • You can find the same object database in your local repository in the (hidden) .git folder Commented Mar 17, 2013 at 17:58

2 Answers 2

24

You've created a remote repository without a working directory (which is the purpose of the --bare option). What you need to do next is clone that remote repository into your website directory. I use the same approach; I have a ~/git directory with one or more bare git repositories and then clones for one or more web sites. Your steps could be:

# locate your bare repository in a 'git' directory
remote$ mkdir ~/git; mkdir ~/git/mywebsite.git; cd ~/git/mywebsite.git; git init --bare
# set this up as your remote
local$ git remote add origin ssh:.../git/mywebsite.git
local$ git push origin ...
# on the remote, clone into your working website
remote$ cd ~/public_html
remote$ git clone ~/git/mywebsite.git mywebsite

Using this approach you can develop locally, push to remote as often as you like and then, when you are ready, git pull on the remote to actually update the website.

answered Mar 17, 2013 at 17:40

1 Comment

Thank you, I nearly gave up looking for this answer! Could anyone explain the logic behind this though? Why is the new file repository cloned from the remote bare repository? If anything it seems to me to have more of a resemblence to the local repository.
0

This will answer your question

http://www.saintsjd.com/2011/01/what-is-a-bare-git-repository/

In bare repository you don't need to have source.

answered Aug 22, 2013 at 7:53

1 Comment

As links are not permanent it would be useful if you could copy the relevant details, such as the commands into this answer. I would happily vote up your answer if it had some more detail! An answer can be supported by a link but it should be able to stand alone without it.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.