你如何使用“git --bare init”库? [英] How do you use "git --bare init" repository?

查看:606
本文介绍了你如何使用“git --bare init”库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我创建了一个裸仓库(在我的git服务器中,机器2 ):

  $ mkdir test_repo 
$ git --bare init

现在我需要将文件从本地存储库(计算机1)推送到裸存储库(计算机2)。我可以通过SSH访问机器2。问题是,我认为我不明白裸仓库的概念......



将我的代码存储在裸仓库中的正确方法是什么?如何将我的本地存储库中的更改推送到裸存储库?



使中央存储库具有裸存储库的正确方法是什么?



我对这个问题有点困惑。请给我一个线索。

解决方案

首先,要检查,您需要更改到您创建的目录在运行 git init --bare 之前。另外,传统上给裸露的存储库扩展 .git 。所以你可以做

$ $ p $ g $ git init --bare test_repo.git

对于Git版本< 1.8你会这样做

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' b $ b

要回答您以后的问题,裸仓库(根据定义)没有连接到它们的工作树,所以你不能像在普通的非裸仓库中一样轻松地向它们添加文件(例如,使用 git add 和后续的<$ c $ )你几乎总是通过推送更新裸仓库(使用 git push git commit 。)

/ code>)。



请注意,在这种情况下,您需要先让人们推送到您的存储库。当在 test_repo.git 中时,请执行

  git config receive.denyCurrentBranch ignore 

社群编辑

  git init --bare --shared = group 

正如prasanthv评论的那样,如果你在工作中这样做,而不是私人家庭项目,这就是你想要的。


I need to create a central Git repository but I'm a little confused...

I have created a bare repository (in my git server, machine 2) with:

$ mkdir test_repo
$ git --bare init

Now I need to push files from my local repository (machine 1) to the bare repository (machine 2). I have access to machine 2 by SSH. The thing is that I think I don't understand the concept of a bare repository...

What is the right way of storing my code in the bare repository? How can I push changes from my local repository to the bare repository?

Is the right way of having a central repository to have a bare repository?

I'm a little confused with this subject. Please give me a clue on this.

解决方案

Firstly, just to check, you need to change into the directory you've created before running git init --bare. Also, it's conventional to give bare repositories the extension .git. So you can do

git init --bare test_repo.git

For Git versions < 1.8 you would do

mkdir test_repo.git
cd test_repo.git
git --bare init

To answer your later questions, bare repositories (by definition) don't have a working tree attached to them, so you can't easily add files to them as you would in a normal non-bare repository (e.g. with git add <file> and a subsequent git commit.)

You almost always update a bare repository by pushing to it (using git push) from another repository.

Note that in this case you'll need to first allow people to push to your repository. When inside test_repo.git, do

git config receive.denyCurrentBranch ignore

Community edit

git init --bare --shared=group

As commented by prasanthv, this is what you want if you are doing this at work, rather than for a private home project.

这篇关于你如何使用“git --bare init”库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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