The problem of deleting the remote branch

本文指导您如何解决Git在克隆仓库时遇到的默认分支删除错误,包括切换默认分支、指定HEAD操作、修改HEAD文件及删除旧分支的步骤。

➜  screenwords git:(master) git push origin :master

remote: error: By default, deleting the current branch is denied, because the next

remote: error: 'git clone' won't result in any file checked out, causing confusion.

remote: error: 

remote: error: You can set 'receive.denyDeleteCurrent' configuration variable to

remote: error: 'warn' or 'ignore' in the remote repository to allow deleting the

remote: error: current branch, with or without a warning message.

remote: error: 

remote: error: To squelch this message, you can set it to 'refuse'.

remote: error: refusing to delete the current branch: refs/heads/master

To root@182.92.243.187:/home/gitrepos/Website.git

 ! [remote rejected] master (deletion of the current branch prohibited)

error: failed to push some refs to 'root@182.92.243.187:/home/gitrepos/Website.git'


---------------------------------------------------------------------------------------------------

First decide which branch should be the default branch when the repository is cloned. I assume new_master for this example.

On one of the clients create the new_master branch on the remote repository, you may use anything for master instead, e.g. a commit or another branch name, or skip this step if you already have a suitable branch on the remote.

git push origin master:new_master

The next step can't be done from remote, so execute the command in your remote repository (e.g. using SSH):

给远程分支指定HEAD的操作只能在远程通过SSH完成。。

cd /path/to/my_git_repo
git symbolic-ref HEAD refs/heads/new_master

Alternatively, change the content of the HEAD file directly.

Back on the client:

git fetch
git remote show origin

You should see that the HEAD points to new_master instead of master (or that HEAD is ambiguous if you set new_master to be master). Now we can remove the old master:

git push origin :master

Git shouldn't complain anymore about the deletion. Finally, set the local refs/remotes/origin/HEAD:

git remote set-head origin -a 这步是根据remote origin的head来设置本地的引用

soho@ubuntu:~/code/x10/codee/iplatform$ git branch | grep -v "deco_master" | xargs git branch -d warning: deleting branch 'BE68-dev-1.0.3' that has been merged to 'refs/remotes/origin/BE68_1.0.3_250612', but not yet merged to HEAD. Deleted branch BE68-dev-1.0.3 (was 2f43e93e1e1). warning: deleting branch 'S4_V1.5.1_M4_V2_V1.5.4' that has been merged to 'refs/remotes/origin/S4_V1.5.1_M4_V2_V1.5.4', but not yet merged to HEAD. Deleted branch S4_V1.5.1_M4_V2_V1.5.4 (was 07faa7b2a84). warning: deleting branch 'X20V5_V1.10.0' that has been merged to 'refs/remotes/origin/X20V5_V1.10.0', but not yet merged to HEAD. Deleted branch X20V5_V1.10.0 (was efd6f7d890f). warning: deleting branch 'deco_x50v1.20_easymesh' that has been merged to 'refs/remotes/origin/deco_x50v1.20_easymesh', but not yet merged to HEAD. Deleted branch deco_x50v1.20_easymesh (was ff1e253ced2). warning: deleting branch 'm4v4_1.1.2' that has been merged to 'refs/remotes/origin/m4v4_1.1.2', but not yet merged to HEAD. Deleted branch m4v4_1.1.2 (was 49b7dc0b5b4). error: The branch 'mtk_be26_v1.12.x' is not fully merged. If you are sure you want to delete it, run 'git branch -D mtk_be26_v1.12.x'. warning: deleting branch 'mtk_be67_v1.11.x' that has been merged to 'refs/remotes/origin/mtk_be67_v1.11.x', but not yet merged to HEAD. Deleted branch mtk_be67_v1.11.x (was c05631cad27). warning: deleting branch 'mtk_be68_v1.12.x' that has been merged to 'refs/remotes/origin/mtk_be68_v1.12.x', but not yet merged to HEAD. Deleted branch mtk_be68_v1.12.x (was 393351a59ae). warning: deleting branch 'rtl_x10-5g_v1_1_10_0' that has been merged to 'refs/remotes/origin/rtl_x10-5g_v1_1_10_0', but not yet merged to HEAD. Deleted branch rtl_x10-5g_v1_1_10_0 (was 7ebbef182b1). warning: deleting branch 'x20v3_1_10_0' that has been merged to 'refs/remotes/origin/x20v3_1_10_0', but not yet merged to HEAD. Deleted branch x20v3_1_10_0 (was 5205c4dd330). warning: deleting branch 'x80_x50v3_1.10.0' that has been merged to 'refs/remotes/origin/x80_x50v3_1.10.0', but not yet merged to HEAD. Deleted branch x80_x50v3_1.10.0 (was 6fa6f340dbc). warning: deleting branch 'x80_x50v3_1.12.0' that has been merged to 'refs/remotes/origin/x80_x50v3_1.12.0', but not yet merged to HEAD. Deleted branch x80_x50v3_1.12.0 (was 9e14455eaef). warning: deleting branch 'x80_x50v3_1.12.x' that has been merged to 'refs/remotes/origin/x80_x50v3_1.12.x', but not yet merged to HEAD. Deleted branch x80_x50v3_1.12.x (was e193b830327). warning: deleting branch 'x80_x50v3_v1.8.0' that has been merged to 'refs/remotes/origin/x80_x50v3_v1.8.0', but not yet merged to HEAD. Deleted branch x80_x50v3_v1.8.0 (was 616253dfeee). warning: deleting branch 'x90_x95_v1.8.0_1.2.4' that has been merged to 'refs/remotes/origin/x90_x95_v1.8.0_1.2.4', but not yet merged to HEAD. Deleted branch x90_x95_v1.8.0_1.2.4 (was 49103b6c8ad). warning: deleting branch 'x90_xe75_1.7.0_tpbr_x68v1_1.2.4' that has been merged to 'refs/remotes/origin/x90_xe75_1.7.0_tpbr_x68v1_1.2.4', but not yet merged to HEAD. Deleted branch x90_xe75_1.7.0_tpbr_x68v1_1.2.4 (was fa3dc064fba). warning: deleting branch 'x90_xe75_v1.10.0' that has been merged to 'refs/remotes/origin/x90_xe75_v1.10.0', but not yet merged to HEAD. Deleted branch x90_xe75_v1.10.0 (was 9dc5eb8049a). warning: deleting branch 'x90_xe75_v1.12.1' that has been merged to 'refs/remotes/origin/x90_xe75_v1.12.1', but not yet merged to HEAD. Deleted branch x90_xe75_v1.12.1 (was a1ed99bdbaf). warning: deleting branch 'x90_xe75_v1.7.0_tpbr_x20v2_1.2.4' that has been merged to 'refs/remotes/origin/x90_xe75_v1.7.0_tpbr_x20v2_1.2.4', but not yet merged to HEAD. Deleted branch x90_xe75_v1.7.0_tpbr_x20v2_1.2.4 (was 7573637c5a2). warning: deleting branch 'x90_xe75_v1.7.0_x68v2_plan1_v1.2.5' that has been merged to 'refs/remotes/origin/x90_xe75_v1.7.0_x68v2_plan1_v1.2.5', but not yet merged to HEAD. Deleted branch x90_xe75_v1.7.0_x68v2_plan1_v1.2.5 (was 26c04029716). warning: deleting branch 'x90_xe75_v1.7.0_x75_1.2.4' that has been merged to 'refs/remotes/origin/x90_xe75_v1.7.0_x75_1.2.4', but not yet merged to HEAD. Deleted branch x90_xe75_v1.7.0_x75_1.2.4 (was fb3f22e1837). soho@ubuntu:~/code/x10/codee/iplatform$ git branch -vv deco_master 785c38761f2 [origin/deco_master] <generic><client-mgmt>Fixed the issue of not being free after malloc <generic><client-mgmt>修复malloc后未free的造成的内存泄漏问题 deco_master.LTE.1.10.0 80a351d8e3f [origin/deco_master.LTE.1.10.0] [generic][iot-network] Fix the Out of Memory issue occurring in BVT automation 修复bvt自动化出现的Out of Memory问题 deco_master.be65v2.sdk12_5 0cfc6215542 [origin/deco_master.be65v2.sdk12_5] <generic><app-dpi<fix>resolve compile problem deco_master.rtl_x10v1_1_10_0_release_CA 1bf1485fe24 [origin/deco_master.rtl_x10v1_1_10_0_release_CA] Revert "[x10-4gv2] Fix Bug 1025576 - Device Isolation: Clients A/B can still ping each other after adding A to isolation list" deco_master.xe200.1.8.0.homeshield 69dbf58e986 [origin/deco_master.xe200.1.8.0.homeshield] [tddp]update tddp submodule node to slove red reset problem deco_master.xe200.1.8.0.homeshield.sfev2.meshopt fa6f64aab0f [origin/deco_master.xe200.1.8.0.homeshield.sfev2.meshopt] fix [Bug 1101770] [P3] NEW: [CNT_Mesh] [XE75 Pro V2] The 6G switch in the wireless Settings cannot be turned on and automatically turns off within 1 second each time it is turned on deco_master.xe200.1.8.0.homeshield.sfev2.meshopt.F_secure.RED 16fcf2b13ba [origin/deco_master.xe200.1.8.0.homeshield.sfev2.meshopt.F_secure.RED] [tddp]更新tddp节点 * deco_master_1.14_x50 c34ea8ecdc3 [origin/deco_master_1.14_x50] Merge "luci-apps: Ipv6 dial-up interaction supports APP to simultaneously issue enable and dial-up configurations" into deco_master_1.14_x50 deco_master_1.6.0.m4v3 dd536b13030 [origin/deco_master_1.6.0.m4v3] <sdk> update submodule deco_master_1.7.x_m5_homecare_upgrade a3af99bc812 [origin/deco_master_1.7.x_m5_homecare_upgrade] Merge "M5 1.0: Update the backup image" into deco_master_1.7.x_m5_homecare_upgrade deco_master_1_10_0.m9_homecare_upgrade 5e52c631d61 [origin/deco_master_1_10_0.m9_homecare_upgrade] guest network: M5 1.0 fixed the issue where guest network clients on wired networking RE could not obtain IP addresses deco_master_1_11_0_x60v3.v1.3.0 1a1a5335b57 [origin/deco_master_1_11_0_x60v3.v1.3.0] [luci-apps] Add 5G bandwidth switching feature for X60 4.2(B4)(2) deco_master_1_6_0.m9_homecare_upgrade 8f2129db8dd [origin/deco_master_1_6_0.m9_homecare_upgrade] guest network: M5 1.0 fixed the issue where guest network clients on wired networking RE could not obtain IP addresses deco_master_e4v2_1.10.0 d138864efc6 [origin/deco_master_e4v2_1.10.0] [wandetect3] pppoe拨号下,不通过network.interface.wan检测拨号情况 deco_master_m4v2_1.8.0 ddc63aa44ae [origin/deco_master_m4v2_1.8.0] product_configs: Enable the CONFIG_PACKAGE_ca-bundle compilation option deco_master_qca_1.12.1 c66eb0930d2 [origin/deco_master_qca_1.12.1] Solve the problem of xml_check compilation syntax error on the Jenkins compilation deco_master_x60v2_1.5.3 074d7baae99 [origin/deco_master_x60v2_1.5.3] <fix> 修复云端更新规则后,无法reload 进程和在AP模式下snort进程会启动的问题 mtk_be26_v1.12.x cd0cc7d407f [origin/mtk_be26_v1.12.x: ahead 4, behind 2] [be26v1&&be25v2][standby][build] EU country code adaptation for the standby function of be26v1 && be25v2 models
最新发布
11-08
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值