You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无需重复输入分支名,Git分支远程跟踪的快捷设置方法

本地分支未跟踪远程同名分支的简化关联命令

当执行git pull时出现如下提示:

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=<remote>/<branch> main

存在更简短的命令,无需手动输入当前分支名即可关联远程同名分支:

  • 使用git branch -u origin/main
    这是git branch --set-upstream-to的简写形式,Git会自动识别当前所在的本地分支,并将其与指定的远程分支origin/main建立跟踪关系。

  • 若需要同时完成拉取和关联,可执行git pull origin main --set-upstream
    该命令在拉取远程origin/main分支内容的同时,自动将当前本地分支设置为跟踪该远程分支,一步完成两个操作。

内容的提问来源于stack exchange,提问作者joachim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 00:44:57