简体   繁体   中英

How to pull a specific branch from Github

There is this repo:

https://github.com/googlesamples/android-architecture

And there is this branch:

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 pull origin todo-mvvm-databinding will fetch and merge this branch into your local one.

The above answer works well but I wanted to post with fetch and checkout which works fine as well.

Step 1: git fetch todo-mvvm-databinding

Step 2: git checkout todo-mvvm-databinding

You are on your todo-mvvm-databinding branch.

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

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:

Make sure to commit all your changes on the current branch as git will throw some errors and warning about uncommited codes. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM