I want to give you onelinerone-liner command for fetching all the remote branches to your local and switch to your desired newly created local branch:
git fetch && git checkout discover
afterAfter running the above command you will get the below message:
Switched to a new branch 'discover'
Branch discover set up to track remote branch discover from origin.
theThe first line states that Switchedswitched to a Newnew branch - why new ? itIt is already there in remote!.
But actually you have to create it locally too, the. The branch is taken from the remote index and created locally for you.
Here discover is a new branch which were created from your repository's remote branch discover.
But the second line gives more information than the first one which tell us that:
ourOur branch is set uptoup to track remote branch with the same name.
Although git fetch fetches all branches to local. But if you run git branch after it, you will see only master branch in local. whyWhy?
becauseBecause for every branch you have in remote you have to create it locally too, for tracking it as git checkout <branchname> as we have done in the above example.
afterAfter running git checkout command you can run git branch, and now you can see both the branch :
- master and 22. discover in your local listing.