git錯誤 You are not currently on a branch的解決辦法


今天使用 git pullgit 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

這三行命令的意思是:

  1. 依據快照bdcfe3d8 創建 temp 分支
  2. 切換到 master 分支
  3. 將 temp 分支合並到 master分支

再看一下所有的分支

git branch
* master
* issue68
* temp

這時候就可以進行 git pullgit push
記得刪除 temp 分支哦

git branch -d temp


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM