[英]How to pull a specific branch from Github
There is this repo:有这个回购:
https://github.com/googlesamples/android-architecture https://github.com/googlesamples/android-architecture
And there is this branch:还有这个分支:
https://github.com/googlesamples/android-architecture/tree/todo-mvvm-databinding/ https://github.com/googlesamples/android-architecture/tree/todo-mvvm-databinding/
I have clone the project but i have only the master.我已经克隆了项目,但我只有主人。 What can i do to get this branch?
我该怎么做才能得到这个分支?
If you did a clone, then all branches should be available to you.如果您进行了克隆,那么您应该可以使用所有分支。 You need to checkout the branch.
您需要结帐分支。
git checkout todo-mvvm-databinding
If the branch isn't available for whatever reason, then you can create it and then pull it:如果分支由于某种原因不可用,那么您可以创建它然后拉取它:
git checkout -b todo-mvvm-databinding
( -b
specifies "create branch") git checkout -b todo-mvvm-databinding
( -b
指定“创建分支”)
git pull origin todo-mvvm-databinding
will fetch and merge this branch into your local one. git pull origin todo-mvvm-databinding
将获取此分支并将其合并到您的本地分支中。
The above answer works well but I wanted to post with fetch
and checkout
which works fine as well.上面的答案效果很好,但我想发布
fetch
和checkout
也可以正常工作。
Step 1: git fetch todo-mvvm-databinding
第一步:
git fetch todo-mvvm-databinding
Step 2: git checkout todo-mvvm-databinding
第二步:
git checkout todo-mvvm-databinding
You are on your todo-mvvm-databinding
branch.您在
todo-mvvm-databinding
分支上。
Most of those above methods works but I would like to present this approach which worked well for me.上述大多数方法都有效,但我想介绍这种对我来说效果很好的方法。
Step 1: List all remote branches that are available第 1 步:列出所有可用的远程分支
git fetch
git branch -r
The out put may look as shown below depending on available remote branches for your project.根据项目可用的远程分支,输出可能如下所示。
origin/HEAD -> origin/master
origin/develop
origin/feature/modular_approach
origin/master
Step 2:第 2 步:
Make sure to commit all your changes on the current branch as git will throw some errors and warning about uncommited codes.确保在当前分支上提交所有更改,因为 git 会抛出一些关于未提交代码的错误和警告。 Select a branch and run this command.
选择一个分支并运行此命令。
git checkout origin/feature/modular_approach
If the branch you want to retrieve does not exist locally but is present on the remote.如果您要检索的分支在本地不存在但存在于远程。
Create a branch with exactly the same name as your local remote branch创建一个与本地远程分支同名的分支
git checkout name_remote_branch
Make a pull on this new branch拉动这个新分支
git pull
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.