如何为新项目创建新的空分支 [英] How to create a new empty branch for a new project

查看:98
本文介绍了如何为新项目创建新的空分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用git存储库来存储我们的项目。我们有我们的分支从原始分支出发。但是现在我们想创建一个小的新项目来跟踪一些文档。为此,我们希望创建一个新的空分支来开始存储我们的文件,并且我希望网络的其他用户克隆该分支。



我们该怎么做

我尝试了一些东西,但它们没有奏效。

  $ mkdir proj_doc; cd proj_doc 
$ git init
$ git add。
$ git commit -m'第一次提交'
$ git br proj_doc
$ git co proj_doc
$ git br -d master
$ git push origin proj_doc

它似乎推动分支行,但是当我执行抓取或拉取时,它会从其他分支下载信息,然后我也从其他项目中获得一些额外的文件。什么是最好的解决方案?

解决方案

您可以创建一个分支作为孤儿:

  git checkout --orphan< branchname> 

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

  git rm --cached -r。 

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



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


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.

How can we do that?

I tried some things, but they didnt 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 .

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.

这篇关于如何为新项目创建新的空分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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