今天使用 git pull和git push 命令,分別報錯:
You are not currently on a branch, so I cannot use any
'branch.<branchname>.merge' in your configuration file.
Please specify which remote branch you want to use on the command
line and try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use
git push origin HEAD:<name-of-remote-branch>
這是什么意思呢?
說我當前不是在分支上,因此不能 pull 或者 push
然后利用git branch查看一下,發現:
git branch
* (HEAD detached from bdcfe3d8)
* master
* issue68
我當前所處的位置是在HEAD detached from bdcfe3d8上
所以進行如下操作
git branch temp bdcfe3d8
git checkout master
git merge temp
這三行命令的意思是:
- 依據快照bdcfe3d8 創建 temp 分支
- 切換到 master 分支
- 將 temp 分支合並到 master分支
再看一下所有的分支
git branch
* master
* issue68
* temp
這時候就可以進行 git pull 和 git push 了
記得刪除 temp 分支哦
git branch -d temp
