如何使用git将本地存储库复制到远程服务器? [英] How to copy a local repository to remote server using git?

查看:89
本文介绍了如何使用git将本地存储库复制到远程服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



所以这是我在 local

中完成的工作, / b>文件夹mywebsite /:

  git init 
git add。
git commit -m初始提交

然后,在我的网络服务器

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

然后,在我的本地文件夹mywebsite /:

  git remote add remote_mywebsite ssh://user@domain.com:port /〜/ public_html / myrepo.git 
git push remote_mywebsite master

给出了这个结果:

 计数对象:89,完成。 
使用多达4个线程的增量压缩。
压缩对象:100%(74/74),完成。
写作对象:100%(89/89),61.94 KiB,完成。
总计89(增量2),重用0(增量0)
到ssh://user@domain.com:8943 /〜/ public_html / myrepo.git
* [new branch]主人 - > master

git pull remote_mywebsite

但是当我登录到我的web服务器,在myrepo.git中,我仍然有这些文件和文件夹

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

并且我不检索我在本地mywebsite文件夹中的文件和文件夹。



我如何在远程myrepo.git文件夹中检索我的代码?我做错了什么?



非常感谢您的帮助!

解决方案

您创建了一个没有工作目录的远程存储库(这是 - bare 选项的用途)。接下来需要做的是将该远程存储库克隆到您的网站目录中。我使用相同的方法;我有一个包含一个或多个裸git存储库的〜/ git目录,然后克隆一个或多个网站。你的步骤可能是:

$ p $ #在'git'目录中找到你的仓库
remote $ mkdir〜/ git ; mkdir〜/ git / mywebsite.git; cd〜/ git / mywebsite.git; git init --bare

#将此设置为您的远程
local $ git remote add origin ssh:... / git / mywebsite.git
local $ git push origin ...

#在远程,克隆到您的工作网站
远程$ cd〜/ public_html
远程$ git克隆〜/ git / mywebsite.git mywebsite

使用这种方法,您可以在本地进行开发,随时随地推送到远程,然后当您准备好时, git pull 在遥控器上实际更新网站。


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://user@domain.com: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://user@domain.com: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!

解决方案

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.

这篇关于如何使用git将本地存储库复制到远程服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆