在本地服务器和本地PC上使用GIT [英] Using GIT on local server and local PC

查看:284
本文介绍了在本地服务器和本地PC上使用GIT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试GIT,但遇到了问题.

I'm trying GIT and i ran into an issue.

我有我的本地计算机(我们称其为MAC)和一台服务器(我们将其称为SERVER).这是一台本地服务器,我可以通过桌面上的别名来访问它.

I have my local machine (let's call it MAC) and a server (let's call it SERVER). It's a local server, I access it through an alias in my desktop.

我想在此SERVER中创建一个GIT存储库,在其中保存我的文件并将这些文件拉到我的MAC中.然后,在编辑之后,我要将这些更改提交到SERVER.

I want to create a GIT repository in this SERVER, in which I'll keep my files and pull these files into my MAC. Then, after editing, I want to commit these changes to SERVER.

SERVER        MAC         SERVER
source  -->>  copy  -->>  commit

听起来很像GIT,但是我只能找到有关远程服务器的这些教程,包括登录名和密码等.如何使用本地服务器做到这一点?

It sounds very GIT-like, but I can only find these tutorials for remote servers, with logins and passwords and such. How to do that with a local server?

其他人使用此本地服务器,如果他们能够拉并提交相同的SERVER存储库,那就太好了.

Other people use this local server and it would be nice if they could pull and commit this same SERVER repository.

非常感谢.

ps:我正在使用SourceTree GUI,但对终端并不陌生.

ps: I'm using SourceTree GUI but I'm no stranger to terminal.

推荐答案

访问本地和远程服务器上的中央Git存储库没有区别.在任何情况下,所有教程均有效.对于基本访问,您只需要:

There is no difference in accessing a central Git repository on local and remote servers. All tutorials are valid in either case. For the basic access you simply need:

  1. 在服务器上创建一个普通用户帐户(例如git或george).
  2. 设置对该帐户的SSH密钥访问.在线有很多教程,只需选择其中一个即可.例如 Github教程.目的是当您在Mac上时,只需使用密钥就可以SSH到服务器上的用户帐户而无需用户名/密码.
  3. 登录服务器上的用户帐户,创建一个裸露的Git存储库.
  1. Create a normal user account on the server (e.g. git or george).
  2. Set up a SSH key access to that account. There are many tutorials online, just pick one. For example Github tutorial. The objective is that when you are on your Mac you can SSH to the user account on the server without a username/password, just with the key.
  3. Login to the user account on the server create a bare Git repository.

就是这样,然后您可以从Mac访问该存储库.

That's it, then you can access that repository from your Mac.

例如,假设服务器名称为myserver.com,其IP为192.168.1.50.您通过SSH登录到该服务器:

For example, assume that the server name is myserver.com and it's IP is 192.168.1.50. You login to that server over SSH:

ssh george@192.168.1.50

如果密钥设置正确,则您现在已登录(不提供用户名/密码).现在创建裸仓库:

If the key is set up correctly, you are now logged in (without providing username/password). Now create the bare repository:

mkdir mygit
cd mygit
mkdir myrepository.git
cd myrepository.git/
git --bare init

然后在Mac上创建一个新的存储库:

Then on the Mac create a new repository:

mkdir mylocalrepo
cd mylocalrepo
git init
echo "sometext" > firstfile.txt
git add firstfile.txt
git commit -m "First commit"

现在,您可以将在服务器上创建的存储库指定为本地存储库的远程存储库.在Mac上(或要在其上访问该存储库的任何其他计算机上):

Now you can specify the repository created on the server as the remote repository for your local repository. On your Mac (or any other machine on which you want to access that repository):

git remote add origin george@192.168.1.50:mygit/myrepository.git
git push origin master

或者,使用服务器名称而不是IP,并使用其他远程名称:

Alternatively, use the server name rather than IP, and a different remote name:

git remote add origin2 george@myserver.com:mygit/myrepository.git
git push origin2 master

一旦掌握了这些基本知识,便可以开始考虑添加WWW界面了.

Once you have those basics working you can then start thinking about adding a WWW interface.

这篇关于在本地服务器和本地PC上使用GIT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆