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
Git push/clone to new server
提问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 clone
from the other machine.
我只是在学习 Git,有些东西我无法解决。在 Mac 本地创建和使用 git 存储库后,我可以将副本推送到其他地方的另一台服务器吗?我在防火墙后面,所以不幸的是我不能git clone
从另一台机器上运行。
回答by hobbs
git remote add
nameurlgit push
namebranch
git remote add
名称网址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 origin
is special. Just git push
alone will do the same as git push origin
thisbranch(for whatever branch you're on).
请参阅文档git push
- 您可以将远程设置为给定分支的默认远程;如果你不这样做,这个名字origin
很特别。只是git push
单单会做同样的git push origin
thisbranch(无论何种分支你上)。
回答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 bundle
is 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 .git
directory 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
.
回答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