您使用哪种服务器托管Git存储库?
这可能是可以想象的最基本的git问题.
This is probably the most elementary git question imaginable.
假设我启动了一个项目,并在我的VPS主机上为其创建了一个Git存储库.
Let's say I start a project and create a Git repository for it on my VPS host.
在SVN中,您可以运行SVN服务器,通过Apache服务SVN,通过ssh连接到存储库.
In SVN you can run an SVN server, serve SVN over Apache, connect to the repo over ssh.
Git与之类似的是什么?我需要运行一个Git守护进程吗?是否有 git://
协议?
What is the Git analogy to that? Do I need to run a Git daemon? Is there a git://
protocol?
还是在我的开发机器上运行 $ git xyz
命令,它们通过ssh在幕后进行通信?
Or is it that on my dev machine I run $ git xyz
commands and they communicate under the hood via ssh?
(顺便说一句,我需要托管自己的存储库.GitHub很棒,它不适合我的项目.)
(BTW, I need to host my own repository. GitHub is great, it isn't a good fit for my projects.)
如果有问题,CentOS Linux中的VPS机器和dev机器是OS X.
In case it matters, VPS machine in CentOS Linux and dev machine is OS X.
托管git repo的最简单方法是通过ssh.
The easiest way to host a git repo is over ssh.
在您的服务器上,使用以下命令创建一个空的存储库:
On your server, create an empty repository with:
cd my_project_folder
git init --shared --bare
在您的开发机上,克隆空的存储库并开始使用它.
on your dev machine, clone the empty repository and start using it.
git clone username@myserver:my_project_folder
其中用户名是您的ssh用户名,而myserver是您的服务器主机.
Where username is your ssh username and myserver is your server host.
现在您有了存储库的副本,添加文件并进行第一次提交,例如
Now you have a copy of the repository, add your files and make a first commit e.g.
cd my_project_folder
touch README
git add README
git commit -m'Initial Commit'
git push origin master # push to your server
如果您查看 .git/config
文件,则会看到为您指向服务器自动设置了远程"主机.
If you look in the .git/config
file, you'll see that a "remote" host is automatically set up for you pointing to your server.