如何将远程 Git 存储库添加到 Ubuntu 服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5136381/
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
How do I add a remote Git repository to an Ubuntu Server?
提问by Jonas
I have created a Git repository on my Desktop machine (Windows 7) with:
我在我的台式机(Windows 7)上创建了一个 Git 存储库:
git init
git add <all my files>
git commit -m "added my files"
Now I have installed a new Ubuntu Server 10.10 on a machine on my LAN and installed OpenSSH. My home directory is /home/jonas
and I created a directory ~/code/
to contain my projects. I can log in to the Ubuntu Server from Windows 7 with Putty.
现在我已经在 LAN 上的一台机器上安装了一个新的 Ubuntu Server 10.10 并安装了 OpenSSH。我的主目录是/home/jonas
,我创建了一个目录~/code/
来包含我的项目。我可以使用 Putty 从 Windows 7 登录到 Ubuntu 服务器。
I installed Git on the server with sudo apt-get install git
我在服务器上安装了 Git sudo apt-get install git
Adding a remote repository
添加远程仓库
Now I want to add my Git repository on my Desktop to the Server. I tried to follow the instructions from Pragmatic Version Control Using Git.
现在我想将我桌面上的 Git 存储库添加到服务器。我尝试按照使用 Git 的实用版本控制中的说明进行操作。
From my Desktop I run these commands:
我从我的桌面运行这些命令:
git remote add origin [email protected]/home/jonas/code/myproject.git
git push origin master
But I got this error message:
但我收到此错误消息:
fatal: '[email protected]/home/jonas/code/myproject.git' does not appear to be
a git repository
fatal: The remote end hung up unexpectedly
What is the problem? How do I create the remote repository?
问题是什么?如何创建远程存储库?
As PerfectlyNormal suggested, I added a :
in the address. Now it worked better, and I had to type my password to the server, but then I got a similar error message:
正如 PerfectlyNormal 所建议的,我:
在地址中添加了一个。现在它工作得更好了,我不得不在服务器上输入我的密码,但随后我收到了类似的错误消息:
fatal: '/home/jonas/code/myproject.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
Do I have to initialize a Git repository on the server before I can git push
to it?
我是否必须先在服务器上初始化 Git 存储库,然后才能 git push
使用它?
采纳答案by Andrew Marshall
Did you setup the repository on the remote server? You need to run
您是否在远程服务器上设置了存储库?你需要跑
mkdir -p /home/jonas/code/myproject.git
cd /home/jonas/code/myproject.git
git init --bare
on the server in order to set it up. I recommend taking a look at how to setup a git server in the free ProGit book.
在服务器上进行设置。我建议在免费的ProGit 书籍中查看如何设置 git 服务器。
回答by Arrowmaster
git remote add origin [email protected]/home/jonas/code/myproject.git
When using SSH, remote repository addresses can be expressed in two ways. One using absolute paths and one using relative paths from the users home directory. You've mixed them up.
使用 SSH 时,远程存储库地址可以用两种方式表示。一种使用绝对路径,另一种使用来自用户主目录的相对路径。你把它们混在一起了。
The corrected command would be one of the following.
更正后的命令将是以下命令之一。
git remote add origin [email protected]:code/myproject.git
git remote add origin ssh://[email protected]/home/jonas/code/myproject.git
回答by PerfectlyNormal
First thing I notice is that you're missing a ':'. Should be git remote add origin [email protected]:/home/jonas/code/myproject.git
我注意到的第一件事是您缺少一个 ':'。应该git remote add origin [email protected]:/home/jonas/code/myproject.git
回答by Keith John Hutchison
I normally create a bare repository locally and then scp that repository to the server when I'm setting up a remote repository.
我通常在本地创建一个裸存储库,然后在设置远程存储库时将该存储库 scp 到服务器。
For example,
例如,
cd c:\gits
git clone --bare c:\path\to\local\repository\some_project
which creates some_project.git.
它创建了 some_project.git。
Then,
然后,
scp -r some_project.git [email protected]:/path/to/remote/gits/.
enter your password or maybe you already have public/private key access working.
输入您的密码,或者您可能已经拥有公钥/私钥访问权限。
回答by Dan D.
you need a colon:
你需要一个冒号:
git remote add origin [email protected]/home/jonas/code/myproject.git
should be:
应该:
git remote add origin [email protected]:/home/jonas/code/myproject.git
回答by Joel Purra
Have a look at the handy script git-create.bash
by Eike Kettner
. Give it your preferred remote address ([email protected]:code/myproject.git
), and it will automatically SSH in to create the directory and initialize an empty --bare
repository for you. All you need to do is add the git remote
and git push
.
看看由Eike Kettner
编写的方便的脚本git-create.bash
。给它你的首选远程地址 ( ),它会自动通过 SSH 连接来创建目录并为你初始化一个空的存储库。您需要做的就是添加和。[email protected]:code/myproject.git
--bare
git remote
git push
git-create.bash
: Create new empty remote git repository via ssh
git-create.bash
: 通过 ssh 创建新的空远程 git 存储库
Usage:
用法:
git-create.bash '[email protected]:code/myproject.git'
git remote add origin '[email protected]:code/myproject.git'
git push -u origin master
回答by KRIPA SHANKAR JHA
Connecting your Local Repo. to Git Remote Server Ubuntu
Create a User in remote server and assign permission for ssh access using
ssh-keygen
in your local server and paste, its.pub
file to ssh of the remote server.
连接您的本地仓库。到 Git 远程服务器 Ubuntu
在远程服务器上创建一个用户,并
ssh-keygen
在本地服务器中使用 ssh 访问分配权限,然后将其.pub
文件粘贴到远程服务器的 ssh 中。
Things to do on remote Server
在远程服务器上要做的事情
Server : XX.XXX.1XX.XX
服务器 : XX.XXX.1XX.XX
Inside Putty command line
在 Putty 命令行中
Go to location :
cd ~/srv/git
srv in your root directoryMake a folder : mkdir your_file_name followed by cd inside your file inside your git folder
initialize git there : git init --bare
Done
转到位置:
cd ~/srv/git
根目录中的 srv创建一个文件夹: mkdir your_file_name 后跟 cd 在git 文件夹内的文件中
在那里初始化 git : git init --bare
Done
Things to do On Local Machine
在本地机器上要做的事情
create your repository ..
initializing Git:
git init
Create the remote connection :
git remote add origin [email protected]:/srv/git/your_file_name
git push.
Done
创建您的存储库..
初始化 Git:
git init
创建远程连接:
git remote add origin [email protected]:/srv/git/your_file_name
推。
Done
If you got stuck any point refer :https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server.
如果您遇到任何问题,请参考:https: //git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server。