如何在使用“git pull”时将Git配置为自动从当前分支拉出? [英] How do I configure Git to automatically pull from current branch when using "git pull"?

查看:377
本文介绍了如何在使用“git pull”时将Git配置为自动从当前分支拉出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用我们当前的设置,你必须输入分支名称(例如: git pull origin feature-branch ),我已经犯了错误从一个分支到另一个分支,意外地将两个分支合并为两个完全不同的版本。我想通过配置Git来避免这种情况,只需键入 git pull 就可以将您当前的分支。

With our current setup you always have to enter the branch name (ie: git pull origin feature-branch" when doing a pull. I've already made the mistake of pulling from one branch into another, accidentally merging two branches with two very different releases. I'd like to avoid this by configuring Git so that simply typing git pull will pull the current branch you're in.

我该如何做?

How do I do this?

推荐答案

您可以创建一个跟踪分支。从Git Book( http:// git-scm .com / book / en / Git-Branching-Remote-Branches ): b
$ b

You can create a tracking branch. From the Git Book (http://git-scm.com/book/en/Git-Branching-Remote-Branches):


当你克隆版本库时,自动创建一个跟踪 origin / master
master 分支,这就是为什么 git推送
git pull 无需其他参数即可使用,但您可以设置
如果您愿意的话,可以使用其他跟踪分支 - 那些不跟踪原点上的
分支并且不跟踪 master 分支。简单的
例子就是刚才看到的例子,运行
git checkout -b [branch] [remotename] / [branch] 。如果您有Git
版本1.6.2或更高版本,您还可以使用 - track 简写:

When you clone a repository, it generally automatically creates a master branch that tracks origin/master. That’s why git push and git pull work out of the box with no other arguments. However, you can set up other tracking branches if you wish — ones that don’t track branches on origin and don’t track the master branch. The simple case is the example you just saw, running git checkout -b [branch] [remotename]/[branch]. If you have Git version 1.6.2 or later, you can also use the --track shorthand:

$ git checkout --track origin/serverfix
Branch serverfix set up to track remote branch refs/remotes/origin/serverfix.
Switched to a new branch "serverfix"


这篇关于如何在使用“git pull”时将Git配置为自动从当前分支拉出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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