git 如何只拉取当前分支?
有没有一种配置方法可以设置它而无需指定哪个分支?
Is there a config way to set this up without having to specify which branch?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有没有一种配置方法可以设置它而无需指定哪个分支?
Is there a config way to set this up without having to specify which branch?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
Git 已经只拉取当前分支。如果您将分支设置为跟踪分支,则无需指定远程分支。
git Branch --set-upstream-to=reponame/remotebranch localbranch
将设置跟踪关系。然后,您发出 git pull [--rebase] ,并且只有该分支会被更新。当然,所有远程跟踪分支和远程的所有引用都将被更新,但只有本地跟踪分支将被修改。
有用的 Bash 别名可以减少此常见操作的输入:
执行相同操作的 Powershell 函数:
Git already only pulls the current branch. If you have branch set up as a tracking branch, you do not need to specify the remote branch.
git branch --set-upstream-to=reponame/remotebranch localbranch
will set up the tracking relationship. You then issuegit pull [--rebase]
and only that branch will be updated.Of course, all remote tracking branches and all refs for the remote will be updated, but only your local tracking branch will be modified.
Useful Bash alias to cut down on typing of this common operation:
Powershell function that does the same:
我只是这样做的:
或者
这从 git 分支中提取当前分支,并从远程源中提取该分支。
请注意,就像 Seth Robertson 所说,当没有给出参数时,仅修改当前分支,但会获取所有远程分支。我不想获取所有远程分支,所以我这样做了。
I just did it this way:
or
This extracts the current branch from
git branch
, and pulls that branch from remote origin.Note, that like Seth Robertson said, when no arguments are given only the current branch is modified but all remote branches are fetched. I don't want to fetch all remote branches, so I did it this way.
更新
我添加的旧答案不再有效:/。但是在收到一些关于我放置的 PUSH 版本的赞成票后,对我来说意味着这个答案实际上是在帮助那些从搜索引擎来到这里的人,所以我会保留这个答案。
尝试这个新版本git:
UPDATE
The old answer i've add does not work any more :/. But after receive some upvotes about the PUSH version I've placed, to me means this answer is actually helping someone that ending coming here from search engines, so I'll keep this answer.
Try this for the new version of git:
--set-upstream
标志已弃用并将被删除。因此,请使用
--track
或--set-upstream-to
示例:
如果您想为此分支设置跟踪信息,可以使用以下命令:
The
--set-upstream
flag is deprecated and will be removed.Hence, use
--track
or--set-upstream-to
Example:
If you wish to set tracking information for this branch you can do so with:
这是一个 git 别名,它不假设远程是
origin
,并在分支未跟踪远程时进行处理。pullh = "!f() { set -e; set -o pipelinefail; arr=($(git rev-parse --abbrev-ref @{u} | sed 's/\\//\\n /')); git pull ${arr[0]} ${arr[1]}; f"
(免责声明:我是一个 bash 新手,上面的内容可能会简化很多.)
Here's a git alias that doesn't assume the remote is
origin
and handles if the branch isn't tracking a remote.pullh = "!f() { set -e; set -o pipefail; arr=($(git rev-parse --abbrev-ref @{u} | sed 's/\\//\\n/')); git pull ${arr[0]} ${arr[1]}; }; f"
(Disclaimer: I'm very much a bash novice and the above could probably be simplified a lot.)
是的,有一个可以在 .gitconfig 中更改的配置,例如:
它将推送当前分支以更新接收端具有相同名称的分支。
检查方式:
请参阅:git-config。
Yes, there is a config which can be changed in
.gitconfig
, for example:which would push the current branch to update a branch with the same name on the receiving end.
Check by:
See: git-config.