create git init --bare 时如何设置源目录的存放目录?

How do I set the source directory's storage directory when I create git init --bare?

我使用git init --bare在linux上创建了一个裸仓库,但是我想同时设置它的源目录位置,这样虽然裸仓库只保存git提交记录,我直接在linux上做。找到源代码。

裸仓库没有默认工作树,但您可以添加一个或任意多个。

如果您从头开始创建一个裸仓库,它还没有任何提交。您需要从另一个存储库推送提交或在裸存储库中至少创建一个。

# 1. push from another repository "bar"
cd /path/to/bar
git push /path/to/foo master

# add a worktree for "master"
cd /path/to/foo
git worktree add /path/to/worktree master

# ------------------------------------------------

# 2. create commit from the bare repository "foo"
cd /path/to/foo

# create the empty tree
tree=$(git hash-object -w -t tree --stdin < /dev/null)

# create a commit from the tree
commit=$(git commit-tree -m "initial commit" $tree)

# create "master" from the commit
git update-ref refs/heads/master $commit

# add a worktree for "master"
git worktree add /path/to/worktree master

但是现在,如果您克隆 /path/to/foo 并进行提交,然后将 master 推回到 /path/to/foo,工作树 /path/to/worktree 中的状态会有点奇怪。您需要 运行 git reset --hard/path/to/worktree 中更新其状态和代码。

除了工作树,您还可以从 /path/to/foo.

进行克隆
git clone /path/to/foo worktree
cd worktree
# checkout branch "master", which should be already checked out by default
git checkout master
# update "master"
git pull origin master
# update other branches
git fetch
# checkout a new branch "dev" which has been pushed to /path/to/foo
git checkout dev