为新项目创建一个新的空分支

问题描述:

我们正在使用git存储库来存储我们的项目。我们的分支机构与原始分支机构不同。但是现在我们要创建一个小的新项目来跟踪一些文档。为此,我们希望创建一个新的空分支来开始存储文件,我希望网络中的其他用户克隆该分支。

We are using a git repository to store our project. We have our branches departing from the original branch. But now we want to create a small new project to track some documentation. For that we would want to create a new empty branch to start storing our files, and I would want other users of the network to clone that branch.

我们该怎么做

我尝试了一些操作,但是没有用。

I tried some things, but they didn't work.

$ mkdir proj_doc; cd proj_doc
$ git init
$ git add .
$ git commit -m 'first commit'
$ git br proj_doc
$ git co proj_doc
$ git br -d master
$ git push origin proj_doc

似乎可以使分支正常运行,但是当我执行访存操作时,它会从其他分支下载信息,然后我还从其他项目中获得了一些额外的文件。最好的解决方案是什么?

It seems to push the branch ok, but when I do a fetch or pull, it downloads information from other branches, and then I also get some extra files from other projects. What's the best solution?

您可以将分支创建为孤儿:

You can create a branch as an orphan:

git checkout --orphan <branchname>

这将创建一个没有父母的新分支。然后,您可以使用以下命令清除工作目录:

This will create a new branch with no parents. Then, you can clear the working directory with:

git rm --cached -r .

并添加文档文件,提交并推送到github。

and add the documentation files, commit them and push them up to github.

拉取或提取将始终更新有关所有远程分支的本地信息。如果只想提取/获取单个远程分支的信息,则需要指定它。

A pull or fetch will always update the local information about all the remote branches. If you only want to pull/fetch the information for a single remote branch, you need to specify it.