你如何创建一个远程Git分支? [英] How do you create a remote Git branch?

查看:97
本文介绍了你如何创建一个远程Git分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个本地分支,我想推上游。关于如何跟踪新创建的远程分支,Stack Overflow存在类似的问题。

但是,我的工作流程略有不同。 第一我想创建一个本地分支,当我满意并且想要分享我的分支时,我只会向上推它。




  • 我该怎么做? (我的谷歌搜索似乎没有提供任何东西)。


我如何告诉我的同事将它从上游存储库中取出? >

更新使用Git 2.0有一个更简单的答案我已经在下面写了: https://stackoverflow.com/a/27185855/109305

解决方案

简单的Git 2.0+解决方案:



Git 2.0的行为变得更简单

您可以使用 push.default = current 配置git使生活更轻松:

我加入这样我现在就可以用

  $ git push -u 

-u 会跟踪同名远程分支。否,使用此配置,您将自动猜测对git push的远程引用。从 git.config文档



< blockquote>

push.default



定义git push在没有明确给出refspec时应该采取的行动。 p>

push.default = current - 推送当前分支以更新
在接收端名称相同。适用于中央和非中央工作流程。


对我而言,这是对我日常Git工作流程的简化。配置设置将在本地添加分支并希望远程创建分支时使用常规用例。另外,我可以通过做 git co remote_branch_name (而不是使用 - set-upstream-to 标志)。



我知道这个问题,并且接受的答案相当老,但行为已经改变,所以现在存在配置选项以使您的工作流程更简单。



要添加到您的全局Git配置,请在命令行上运行此命令:

  $ git config --global push.default current 


I created a local branch which I want to 'push' upstream. There is a similar question here on Stack Overflow on how to track a newly created remote branch.

However, my workflow is slightly different. First I want to create a local branch, and I will only push it upstream when I'm satisfied and want to share my branch.

  • How would I do that? (my google searches did not seem to come up with anything).
  • How would I tell my colleagues to pull it from the upstream repository?

UPDATE With Git 2.0 there is a simpler answer I have written below: https://stackoverflow.com/a/27185855/109305

解决方案

Simple Git 2.0+ solution:

As of Git 2.0 the behaviour has become simpler:

You can configure git with push.default = current to make life easier:

I added this so now I can just push a new branch upstream with

$ git push -u

-u will track remote branch of same name. No with this configuration you will auto-guess the remote reference to git push. From git.config documentation:

push.default

Defines the action git push should take if no refspec is explicitly given.

push.default = current - push the current branch to update a branch with the same name on the receiving end. Works in both central and non-central workflows.

For me, this is a good simplification of my day-to-day Git workflow. The configuration setting takes care of the 'usual' use case where you add a branch locally and want to create it remotely. Also, I can just as easily create local branches from remotes by just doing git co remote_branch_name (as opposed to using --set-upstream-to flag).

I know this question and the accepted answers are rather old, but the behaviour has changed so that now configuration options exists to make your workflow simpler.

To add to your global Git configuration, run this on the command line:

$ git config --global push.default current

这篇关于你如何创建一个远程Git分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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