git 强制推送当前分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11453807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Force push current branch
提问by iblue
I often rebase feature branches and then want to force push them to the server.
我经常 rebase 功能分支,然后想强制将它们推送到服务器。
git push --force origin feature-mongodb-support
Is there any shortcut for git push --force origin <current branch>
?
有什么捷径git push --force origin <current branch>
吗?
采纳答案by Sergey K.
You can use aliases to shorten the command. Use it like this:
您可以使用别名来缩短命令。像这样使用它:
git config --global alias.fpush "push --force origin"
Now to push your branch just type:
现在推送你的分支只需输入:
git fpush feature-mongodb-support
Or you can even hardcode the branch name into the command:
或者您甚至可以将分支名称硬编码到命令中:
git alias fpush "push --force origin feature-mongodb-support"
and use only git fpush
to push your precious work into the upstream.
仅git fpush
用于将您宝贵的工作推向上游。
However, non-fast-forward updates are dangerous since you will basically overwrite all the history on server that occurred between the last merge/rebase into your local branch and the forced push. If you need to do them often there is definitely something wrongin your workflow.
但是,非快进更新是危险的,因为您基本上会覆盖在上次合并/变基到本地分支和强制推送之间发生的服务器上的所有历史记录。如果您需要经常这样做,那么您的工作流程肯定有问题。
回答by jlleblanc
After reading these answers and reading this answer to a related question (https://stackoverflow.com/a/18782415/586), I created this alias to force push to origin
based on the current branch name:
在阅读了这些答案并阅读了相关问题(https://stackoverflow.com/a/18782415/586)的答案后,我创建了这个别名以origin
根据当前分支名称强制推送到:
fp = "!git push -f origin \"$(git rev-parse --abbrev-ref HEAD)\""
回答by Wes Hardaker
This should do the trick:
这应该可以解决问题:
git alias fpush "push --force origin"
Which will let you use git fpush
as a shorter alternative.
这将让您使用git fpush
更短的替代方案。
回答by Lukas
If you use oh my zshyou can simply do
如果你使用oh my zsh你可以简单地做
ggfl
which will do this for you
这将为您做到这一点
git push --force-with-lease origin <your_argument>/$(current_branch)
回答by Irgoff
You can change the default behaviour by setting the push.defaultproperty :
您可以通过设置push.default属性来更改默认行为:
git config --global push.default current
then:
然后:
git push -f
will force a push to you current branch.
将强制推送到您当前的分支。
Here is a copy/paste from http://schacon.github.io/git/git-config.html:
这是来自http://schacon.github.io/git/git-config.html的复制/粘贴:
push.default
Defines the action git push should take if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line. Possible values are:
nothing- do not push anything.
matching- push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default.
upstream- push the current branch to its upstream branch.
tracking- deprecated synonym for upstream.
current- push the current branch to a branch of the same name.
push.default
定义 git push 应该采取的操作,如果命令行上没有给出 refspec,远程中没有配置 refspec,并且命令行上给出的任何选项都没有暗示任何 refspec。可能的值为:
没什么- 不要推任何东西。
匹配- 推送所有匹配的分支。两端具有相同名称的所有分支都被认为是匹配的。这是默认设置。
上游- 将当前分支推送到其上游分支。
跟踪- 不推荐使用的上游同义词。
current- 将当前分支推送到同名分支。
回答by Klas ?.
To automatically force-push to the branch that is tracked(regardless of its name and upstream), I've devised this alias:
为了自动强制推送到被跟踪的分支(不管它的名称和上游),我设计了这个别名:
fbrpush=!git push $(git rev-parse --abbrev-ref=loose --symbolic-full-name @{upstream} \
| sed 's:/: +:')
(line is broken for readability)
(为了可读性而断行)
(based on another SO answer)
(基于另一个 SO 答案)