Git推新的本地分支到远程,而不必指定名称 [英] Git push new local branch to remote, without having to specify name

查看:559
本文介绍了Git推新的本地分支到远程,而不必指定名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在针对特定跟踪问题修补修补程序时,我们的工作流程如下所示:

  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 to upstream/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 for push)

解决方案

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 @ or HEAD, Git will push the currently checked-out branch to origin, and if the branch doesn't exist on origin yet, it will create it.

So, in your example, if you have issue-435-db-integrity-exception checked out, then git push origin @ will make a new branch with the same name on origin.

这篇关于Git推新的本地分支到远程,而不必指定名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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