Git推新的本地分支到远程,而不必指定名称 [英] Git push new local branch to remote, without having to specify name
问题描述
在针对特定跟踪问题修补修补程序时,我们的工作流程如下所示:
1。 git checkout补丁; git拉上游补丁; #确保我们是最新的
2. git checkout -b issue-435-db-integrity-exception
3.#代码一些真棒
4. git commit -am 修复问题#435
5. git push -u原始问题-435-db-integrity-exception
然后我们打开一个从 origin / 435
到 upstream / patch
的请求,这样代码审查可以在GitHub / Bitbucket上进行。然后我们从第一步开始。
但是,虽然听起来有点发嘶声,但如果我们不必明确指定我们想要的远程分支创建:
git push -u原始问题-435-db-integrity-exception
重新输入分支名称并不很有趣,我不同意将它改为 435 或者更紧凑的东西。
有没有办法(1)强制Git将当前分支推送到一个类似命名的分支必要时创建它而不明确命名它?不是全球,只是一种现场的标志。
或者, 2)访问Git别名中的当前分支,并写入如下内容:
[别名]
pnew = push -u origin $(git symbolic-ref --short HEAD)
(但这不起作用 - 它认为 - short
选项适用于 push
)
#For Git 1.8。 5+
$通过使用
git push origin -u @
#对于旧版本的Git
git push origin -u HEAD
@
或HEAD
,Git将会推送当前签出的分支为origin
,并且如果该分支不存在于origin
中,它将创建所以,在你的例子中,如果你有issue-435-db-integrity-exception
检出,然后git push origin @
会在origin
中创建一个同名的新分支。When working on patch fixes for a specific, tracked issue, our workflow looks like:
1. git checkout patch; git pull upstream patch; # make sure we're up-to-date 2. git checkout -b issue-435-db-integrity-exception 3. # code some awesome 4. git commit -am "Fixes issue #435" 5. git push -u origin issue-435-db-integrity-exception
Then we open a pull request from
origin/435
toupstream/patch
, so that the code review can take place on GitHub/Bitbucket. Then we just start over from step #1.But, though it may sound a bit whiny, it would be great if we didn't have to explicitly name the remote branch we want to create:
git push -u origin issue-435-db-integrity-exception
It's not a lot of fun to type that branch name all over again, and I disagree with changing it to just
435
or something more compact.Is there a way to (1) force Git to push the current branch to a similarly named branch, creating it if necessary without explicitly naming it? Not globally, just an on-the-spot kind of flag.
Or, is it possible to (2) access the current branch in a Git alias, and write something like:
[alias] pnew = push -u origin $(git symbolic-ref --short HEAD)
(But this doesn't work - it thinks that the
--short
option is meant forpush
)解决方案You could use the following:
# For Git 1.8.5+ git push origin -u @ # For older versions of Git git push origin -u HEAD
By using
@
orHEAD
, Git will push the currently checked-out branch toorigin
, and if the branch doesn't exist onorigin
yet, it will create it.So, in your example, if you have
issue-435-db-integrity-exception
checked out, thengit push origin @
will make a new branch with the same name onorigin
.这篇关于Git推新的本地分支到远程,而不必指定名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!