Git 推送/克隆到新服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1402390/
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-10 07:00:56  来源:igfitidea点击:

Git push/clone to new server

git

提问by Jacob

I'm just learning Git and there is something I can't work out. After creating and using a git repository locally on my Mac, can I push a copy to another server somewhere else? I am behind a firewall so unfortunately I can't run git clonefrom the other machine.

我只是在学习 Git,有些东西我无法解决。在 Mac 本地创建和使用 git 存储库后,我可以将副本推送到其他地方的另一台服务器吗?我在防火墙后面,所以不幸的是我不能git clone从另一台机器上运行。

回答by hobbs

  1. git remote addnameurl
  2. git pushnamebranch
  1. git remote add名称网址
  2. git push名称分支

Example:

例子:

git remote add origin [email protected]:foo/bar.git
git push origin master

See the docs for git push-- you can set a remote as the default remote for a given branch; if you don't, the name originis special. Just git pushalone will do the same as git push originthisbranch(for whatever branch you're on).

请参阅文档git push- 您可以将远程设置为给定分支的默认远程;如果你不这样做,这个名字origin很特别。只是git push单单会做同样的git push originthisbranch(无论何种分支你上)。

回答by Grant Limberg

What you may want to do is first, on your local machine, make a bare clone of the repository

您可能想要做的是首先在本地机器上制作存储库的裸克隆

git clone --bare /path/to/repo /path/to/bare/repo.git  # don't forget the .git!

Now, archive up the new repo.git directory using tar/gzip or whatever your favorite archiving tool is and then copy the archive to the server.

现在,使用 tar/gzip 或任何您喜欢的归档工具归档新的 repo.git 目录,然后将归档文件复制到服务器。

Unarchive the repo on your server. You'll then need to set up a remote on your local repository:

在您的服务器上取消归档存储库。然后,您需要在本地存储库上设置远程:

git remote add repo-name user@host:/path/to/repo.git #this assumes you're using SSH

You will then be able to push to and pull from the remote repo with:

然后,您将能够通过以下方式推送和拉出远程存储库:

git push repo-name branch-name
git pull repo-name branch-name

回答by Greg Hewgill

There are many ways to move repositories around, git bundleis a nice way if you have insufficient network availability. Since a Git repository is really just a directory full of files, you can "clone" a repository by making a copy of the .gitdirectory in whatever way suits you best.

有很多方法可以移动存储库,git bundle如果网络可用性不足,这是一种很好的方法。由于 Git 存储库实际上只是一个充满文件的目录,因此您可以通过以.git最适合您的方式制作目录的副本来“克隆”存储库。

The most efficient way is to use an external repository somewhere (use GitHubor set up Gitosis), and then git push.

最有效的方法是在某处使用外部存储库(使用GitHub或设置Gitosis),然后git push.

回答by jazzed

remote server> cd /home/ec2-user
remote server> git init --bare --shared  test
add ssh pub key to remote server
local> git remote add aws ssh://ec2-user@<hostorip>:/home/ec2-user/dev/test
local> git push aws master

回答by Cesar

You can push a branch to a remote server, say github. You would first have to do the initial project setup, then clone your project and:

您可以将分支推送到远程服务器,例如github。您首先必须进行初始项目设置,然后克隆您的项目并:

git push <remote repo> <your branch>