背景: 分支整理, 想要在原有GIT项目上创建一个新分支, 但从浏览器端操作, 发现都必须要基于其他分支创建, 这样的话, 新分支会包含旧分支的代码和历史提交信息, 这里想创建一个空白的分支, 尝试了以下方法解决
步骤
-
clone
远程项目: git clone git@172.25.73.100:openlab/openlabtest.git
- 查看分支:
git branch -a
- 创建新分支:
git checkout --orphan IndustrySDT
, 返回Switched to a new branch 'IndustrySDT'
- 删除当前项目文件夹下所有文件:
git rm -rf .
- 提交变更:
git commit -m "new branch for Industry SDT"
- 查看分支:
git branch -a
, 发现此时远端还没有新建分支, 需要提交一个新文件, 才会出现远端分支
- 创建文件: 随便创建一个文件
- 添加:
git add Instruction\ manual.md
- 提交:
git commit -m "新增分支说明书"
- 推送:
git push origin IndustrySDT
- 查看分支:
git branch -a
$ git branch -a
* IndustrySDT
develop
test
remotes/origin/HEAD -> origin/develop
remotes/origin/IndustrySDT
remotes/origin/develop
remotes/origin/master
remotes/origin/taas
remotes/origin/test
- 链接远程:
git branch --set-upstream-to=origin/IndustrySDT IndustrySDT
附:
- 删除远程: g
it push origin --delete test
- 删除本地:
git branch -d test
- 强制删除本地:
git branch -D test