我可以用一个命令销毁并重新创建Git远程分支吗? [英] Can I destroy and recreate a Git remote branch in one command?

查看:134
本文介绍了我可以用一个命令销毁并重新创建Git远程分支吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Git中,我有时在长时间运行的分支上工作。我喜欢随时在主人身上进行重新绑定,以便在我准备就绪时轻松合并。



重新绑定后,我无法将之前推送的分支推送到遥远的,因为我的分支的历史不再与远程的那个分支的历史一致。所以我必须先删除它。



这是我目前的工作流程:

  git checkout my_branch 
git rebase master
git push origin:my_branch#删除分支的远程版本
git push origin my_branch#在此分支上推出我的新版历史记录

是否有可以替换最后两个命令的单个原子命令?

解决方案

如果允许您重写远程分支,您可以使用 git push --force my_remote my_branch


In Git, I sometimes work on long-running branches. I like to rebase on master from time to time to make merging easier when I'm ready.

After rebasing, I can't push a previously-pushed branch to a remote, because my branch's history no longer agrees with the remote's history of that branch. So I have to delete it first.

This is my current workflow:

git checkout my_branch
git rebase master
git push origin :my_branch  # Delete remote version of the branch
git push origin my_branch   # Push up my new version of history on this branch

Is there a single, atomic command that could replace the last two commands?

解决方案

If you are allowed to rewrite the remote branch, you can use git push --force my_remote my_branch.

这篇关于我可以用一个命令销毁并重新创建Git远程分支吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆