我想获取远程存储库的单个分支(不是所有分支),并创建一个本地跟踪分支,该分支可以跟踪对该远程分支的进一步更新。远程存储库中的其他分支非常大,所以我希望避免获取它们。我怎么做呢?
当前回答
git 版本:2.74
我是这样做的:
git remote add [REMOTE-NAME] [REMOTE-URL]
git fetch [REMOTE-NAME] -- [BRANCH]
其他回答
一种方法是:
在.git/config中获取远程回购应该设置为获取任何分支:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
获取远程分支:
git fetch origin branch-name
创建一个本地分支'branch-name',用于从原点跟踪远程分支'branch-name'。
git checkout -b branch-name origin/branch-name
列出所有分支
git branch -a
要更新现有的远程跟踪特定的分支,只使用:
git remote set-branches <remote-name> <branch-name>
从git帮助远程:
set-branches
Changes the list of branches tracked by the named remote. This can be used to track a subset of the available remote branches
after the initial setup for a remote.
The named branches will be interpreted as if specified with the -t option on the git remote add command line.
With --add, instead of replacing the list of currently tracked branches, adds to that list.
git fetch <remote_name> <branch_name>
为我工作。
为了完整起见,这里有一个新签出的示例命令:
git clone --branch gh-pages --single-branch git://github.com/user/repo
正如在其他回答中提到的,它设置remote.origin.fetch如下所示:
[remote "origin"]
url = git://github.com/user/repo
fetch = +refs/heads/gh-pages:refs/remotes/origin/gh-pages
我知道已经有很多答案了,但下面这些步骤对我来说是有效的:
Git获取<remote_name> <branch_name> git branch <branch_name> FETCH_HEAD . git Git checkout <branch_name>
这些是基于@Abdulsattar Mohammed的回答,@Christoph对这个回答的评论,以及其他堆栈溢出问题和他们的答案:
如何签出远程Git分支? Git中的FETCH_HEAD是什么意思?
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别