简体   繁体   English

在本地机器上设置git存储库

[英]setting up git repository on local machine

How can I setup a git repository on a local system ? 如何在本地系统上设置git存储库? (I am on a windoze box) (我在防风盒上)

This is the setup I am trying to achieve: (everything is on my local machine) 这是我想要实现的设置:(一切都在我的本地机器上)

  • host folder (which acts like central repository) 主机文件夹(其作用类似于中央存储库)
  • client folder 客户文件夹

I want to do all my dev in the client folder. 我想在客户端文件夹中执行我的所有开发。 Once I am done, I'd like to push it to the host folder. 完成后,我想将其推送到主机文件夹。


This is what I've done: (using git bash on windows) 这就是我所做的:(在Windows上使用git bash)

  • cd d:/adinsert cd d:/ adinsert
  • mkdir host mkdir主持人
    • cd host cd主机
    • git init git init

cd c:/ cd c:/

  • mkdir client mkdir客户端
    • cd client cd客户端
    • git init git init
    • git remote add origin d:/host // Added some files in client folder and commited them git remote add origin d:/ host //在客户端文件夹中添加了一些文件并提交了它们
    • git push origin master git push origin master

When I push stuff to origin, git spits a lot of remote errors. 当我把东西推到原点时,git会吐出很多远程错误。 However, when I make my host a bare git, it pushes successfully. 但是,当我让我的主机成为一个简单的git时,它会成功推送。

I don't understand the difference between regular git and bare git. 我不明白常规git和裸git之间的区别。 From the manual, all I understood was, bare git is used for storing deltas and when you don't want to store original files. 从手册中,我理解的是,裸git用于存储增量,当你不想存储原始文件时。 However, I'd like to store the files in host. 但是,我想将文件存储在主机中。 How can I do that ? 我怎样才能做到这一点 ?

The difference between a "regular git" and a "bare git" is that a bare repository does not have a working directory. “定期混帐”和“裸混帐”之间的区别在于,一个纯仓库没有工作目录。 You should never push into a regular git repository, as you may run into problems that are hard to recover from. 你永远不应该进入常规的git存储库,因为你可能遇到难以恢复的问题。 Always push into a bare repository. 总是进入一个裸存储库。

If you want to have a "host" where copies of your files do appear, then set up a third repository, cloning from the host one. 如果您想要一个“主机”,其中文件的副本确实出现,那么设置第三个存储库,从主机中克隆一个。 Whenever you want to update the host files: 每当您想要更新主机文件时:

  • git push from your working directory to update the main repository git push从您的工作目录git push以更新主存储库
  • git pull from your host directory to pull from the origin git pull从你的主机目录拉出来从原点拉出来

You can even set up a post-commit hook on the bare repository to automatically do the second step. 您甚至可以在裸存储库上设置提交后挂钩以自动执行第二步。

In your client directory you have will notice a .git directory. 在您的client目录中,您将注意到.git目录。 A bare version is basically just that .git directory contents without a working copy. bare版本基本上就是没有工作副本的.git目录内容。

Easiest thing to do would be to clone it (vs trying to setup another repository): 最简单的方法是克隆它(与尝试设置另一个存储库相比):

From c:/ call: 来自c:/ call:

git clone d:/host client

This says clone the 'host' repo and store it under a folder called 'client'. 这表示克隆“主机”仓库并将其存储在名为“客户端”的文件夹下。

Don't create a new git repo in the client folder, clone the host repo 不要在客户端文件夹中创建新的git仓库,克隆主机仓库

cd client
git clone d:/adinsert/host

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

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