How to copy a local repository to remote server using git?
Asked Answered
P

2

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!

Parmentier answered 17/3, 2013 at 17:25 Comment(2)
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.Ceja
You can find the same object database in your local repository in the (hidden) .git folderCeja
A
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.

Adolphadolphe answered 17/3, 2013 at 17:40 Comment(1)
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.Daily
S
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.

Shirleenshirlene answered 22/8, 2013 at 7:53 Comment(1)
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.Yogh

© 2022 - 2024 — McMap. All rights reserved.