一次git分支重命名引发的问题

274 阅读1分钟

前两周居家开发时 由于交流不畅,我把代码写在了错误的分支上 并提交多次。

回公司后发现 交流发现应该用另一个分支。两个分支名字和功能用反了。

想到的方法是checkout 百度一番 发现重命名也可

于是

步骤:

1、将本地分支oldbranch切一个分支到本地

git branch -m oldbranch newbranch

2、删除远程分支

git push --delete origin oldbranch

3、将本地新分支推送到远程

git push origin newbranch

两个分支分别这样处理 似乎成功了。

但是 checkout 分支时 提醒 larances-Mac-mini:tci-api larancegitcheckouttci2104Switchedtobranchtci2104Yourbranchisbasedonorigin/tci2104nolicense,buttheupstreamisgone.(use"gitbranchunsetupstream"tofixup)larancesMacmini:tciapilarance git checkout tci2104 Switched to branch 'tci2104' Your branch is based on 'origin/tci2104-no-license', but the upstream is gone. (use "git branch --unset-upstream" to fixup) larances-Mac-mini:tci-api larance git status On branch tci2104 Your branch is based on 'origin/tci2104-no-license', but the upstream is gone. (use "git branch --unset-upstream" to fixup)

nothing to commit, working tree clean

修改代码提交后提示

larances-Mac-mini:tci-api larance$ git push fatal: The upstream branch of your current branch does not match the name of your current branch. To push to the upstream branch on the remote, use

git push origin HEAD:tci2104-no-license

To push to the branch of the same name on the remote, use

git push origin HEAD

To choose either option permanently, see push.default in 'git help config'.

我不想看到切换分支时的提示 和提交时 强制 写 git push origin HEAD

于是 再次百度,强制指定远程分支,终于搞定

git push --set-upstream origin tci2104-nolicense