如何在没有工作目录的情况下创建git repo? [英] How to create a git repo without a working directory?

查看:204
本文介绍了如何在没有工作目录的情况下创建git repo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用git worktree概念创建多个工作目录.每个功能和/或错误修复一个. 因此,我将一次创建存储库的git克隆,然后根据需要开始创建工作树.

I use git worktree concept to create multiple working directory. One for each feature and/or bug fix. So I will create a git clone of a repository once, and then I start creating worktree as needed.

当我克隆一个git仓库时,默认情况下会检出一个工作目录-主工作树.我们不使用并且不必要地占用了空间.因此,我正在寻找一种创建git repo的方法,并在开始时将工作目录检出.

When I clone a git repository, by default a working directory is checked out - main worktree. Which we dont use and unnecessarily takes up space. So I am looking for a way to create a git repo with a working directory being checked out at the beginning.

我尝试了git clone --bare <url> ./test-git

实际上创建了一个没有工作目录的git repo,但是我无法从中创建一个git工作树.我经常抛出以下错误-

which actually created a git repo without a working directory but I was not able to create a git worktree out of it. I use to throw the following error -

bash-4.4 [/user/darshan/test-git] $git worktree add -b test-git-worktree.repo ../test-git-worktree origin/repo
Preparing worktree (new branch 'test-git-worktree.repo')
fatal: Not a valid object name: 'origin/repo'.

  1. 我在做什么错了?

我进入了根据git clone bare命令创建的.git目录,发现缺少index文件和lfs目录. 这两项将出现在从完整git克隆创建的.git目录中.

I went inside the .git directory created from git clone bare command and found that there was index file and lfs directory missing. And these two items will be present in the .git directory created from the full git clone.

  1. 这两项表明什么?
  2. 在运行什么git命令时,我会得到这些项目吗?

推荐答案

我们可以使用-

git clone -n <url>

这只会创建一个目录(带有存储库名称),其中包含.git目录.

This just creates a directory (with repository name) with .git directory inside it.

注意:此外,我希望使用git clone --bare还应该提供类似的功能.但是还不能弄清楚.

Note: Furthermore, I hope using git clone --bare should also provide similar functionality. But have not been able to figure that out yet.

这篇关于如何在没有工作目录的情况下创建git repo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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