git错误 You are not currently on a branch的解决办法

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

参考链接:https://blog.csdn.net/zhai_865327/article/details/105031756

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值