如何使用 git 将本地存储库复制到远程服务器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15463795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:19:47  来源:igfitidea点击:

How to copy a local repository to remote server using git?

git

提问by Reveclair

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

我正在尝试使用 git 在我的远程服务器中部署我的本地代码。

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

所以这是我在本地文件夹 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 localfolder mywebsite/ :

然后,在我的本地文件夹 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

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

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

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

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

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

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

Thanks a lot for your help!

非常感谢你的帮助!

回答by GoZoner

You've created a remote repository without a working directory (which is the purpose of the --bareoption). 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:

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

# 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 pullon the remote to actually update the website.

使用这种方法,您可以在本地开发,按您喜欢的频率推送到远程,然后当您准备好时,git pull在远程上实际更新网站。

回答by Nethali

This will answer your question

这将回答您的问题

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

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

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

在裸存储库中,您不需要拥有源代码。