简体   繁体   English

在Amazon EC2上配置git

[英]Configuring git on amazon ec2

I am trying to set up git on amazon ec2 and connect it to my local ubuntu machine. 我正在尝试在Amazon EC2上设置git并将其连接到本地ubuntu机器。 So here is what I have done: 所以这是我所做的:

modified ~/.ssh/config to add my server (I added the following there) 修改~/.ssh/config以添加我的服务器(我在其中添加了以下内容)

Host myServer
Hostname ec2- ... .compute.amazonaws.com
User ubuntu
IdentityFile /path/to/pem-key.pem

Then I ssh to my server with ssh myServer to install git with sudo apt-get install git and go to cd /var/www/ to set up my git with git init . 然后我用ssh myServer ssh到服务器,用sudo apt-get install git并转到cd /var/www/git init设置我的git。 I am not using git init --bare because I already have some code there. 我没有使用git init --bare因为那里已经有一些代码。

Then I am trying to set up git on my local machine: git remote add production myServer:/var/www/ (here is where my local code is and it is with some changes so it is not the same as on the ec2). 然后,我尝试在本地计算机上设置git: git remote add production myServer:/var/www/ (这是我的本地代码所在的位置,它进行了一些更改,因此与ec2上的不一样)。

Up till now there are no errors. 到目前为止,还没有错误。 But when I try to push my local code with git push I am getting: 但是当我尝试使用git push本地代码时,我得到了:

Either specify the URL from the command-line or configure a remote repository using 从命令行指定URL或使用以下命令配置远程存储库

 git remote add <name> <url> 

and then push using the remote name 然后使用远程名称推送

 git push <name> 

Ok, I am trying git push myServer , as it is written in the second suggestion (I already done the first one), I am getting another error: 好的,我正在尝试git push myServer ,因为它是在第二个建议中编写的(我已经做过第一个建议),但出现另一个错误:

warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

fatal: 'myServer' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I am totally lost and I think that I am on the wrong track. 我完全迷失了方向,我认为自己走错了路。 All I want is to setup git to be able to easily push my local changes on the server with git push , git commit on the client and deploy them with git pull on the server. 我想要的是设置git以便能够使用git push ,客户端上的git commit轻松地将我的本地更改推送到服务器上,并通过git pull在服务器上部署它们。

When I try suggestions of Michel and do git remote -v on the client, I get 当我尝试Michel的建议并在客户端上执行git remote -v时,我得到了

production  myServer:/var/www/ (fetch)
production  myServer:/var/www/ (push)

When I do git push production default I get 当我执行git push production default我得到

error: src refspec default does not match any.
error: failed to push some refs to 'myServer:/var/www/

The correct syntax for pushing is 推送的正确语法是

git push <remoteName> <branchName>

You named your remote "production", so 您将远程命名为“生产”,因此

git push production (<branch to push>)

will do the job. 会做的工作。

Additionally you can verify your remotes using 此外,您可以使用以下方式验证您的遥控器

git remote -v

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM