如何创建远程 Git 分支? [英] How do you create a remote Git branch?
问题描述
我创建了一个本地分支,我想将其推"到上游.Stack Overflow 上有一个关于如何跟踪新创建的远程分支的类似问题.
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.
- 我该怎么做?(我的谷歌搜索似乎没有找到任何东西).
- 我该如何告诉我的同事从上游存储库中提取它?
更新 Git 2.0 有一个更简单的答案我写在下面:https://stackoverflow.com/a/27185855/109305
推荐答案
简单的Git 2.0+解决方案:
从 Git 2.0 开始,行为变得更简单:
您可以使用 push.default = current
配置 git,让生活更轻松:
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
将跟踪同名的远程分支.现在使用此配置,您将自动猜测对 git push 的远程引用.来自 git.config 文档:
-u
will track remote branch of the same name. Now with this configuration, you will auto-guess the remote reference to git push. From git.config documentation:
push.default
如果没有明确给出 refspec,定义 git push 应该采取的行动.
Defines the action git push should take if no refspec is explicitly given.
push.default = current
- 推送当前分支以更新分支接收端同名.适用于中央和非中央工作流程.
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.
对我来说,这是我日常 Git 工作流程的一个很好的简化.配置设置处理通常"用例,即您在本地添加分支并希望远程创建它.此外,我可以通过执行 git co remote_branch_name
(而不是使用 --set-upstream-to
标志)轻松地从远程创建本地分支.
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 behavior has changed so that now configuration options exist to make your workflow simpler.
要添加到全局 Git 配置,请在命令行上运行:
To add to your global Git configuration, run this on the command line:
$ git config --global push.default current
这篇关于如何创建远程 Git 分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!