1、问题描述:
git提交当前更改的时候显示提交到了”no branch“
- 错误信息->游离的HEAD
Current HEAD is detached, you are working on(no branch).
Do you want to create a branch now?
推送到远程库的时候显示正在尝试将当前游离HEAD(detached HEAD)推送到远程库,但git无法识别目标位置
unable to push to unqualified destination: HEAD
2、解决方法
明确需要本地分支和远程分支,本地分支不影响远程分支,需要提交到远程分支的时候只需要将本地分支与远程分支关联。
- 创建一个新的本地分支并切换到该分支(让HEAD脱离游离状态)
- 在本地分支上提交内容
- 将本地分支与远程分支关联,并推送
git checkout -b newBranch
git commit -m "newInformation"
git branch --set-upstream-to=远程分支的名字 newBranch
git push