Pull to a remote branch that does not exist in my local

18

A co-worker created a branch called feature/validateEmail . I want to do pull or checkout of that branch on my machine to be able to work on it but without waiting for it to do merge a develop or a master .

I tried unsuccessfully:

  • git checkout feature/validateEmail
  • git checkout validateEmail
  • git pull feature/validateEmail
  • git pull validateEmail

And as I use the plugin of oh my zsh I also tried:

  • gco feature/validateEmail
  • gco validateEmail

The branch I can see it with:

  • gba (for the plugin)
  • git branch -a

How can I pull or checkout the remote repository on my machine?

    
asked by Gepser 02.12.2015 в 02:23
source

2 answers

8

First you must make a fetch

git fetch <remoto> <rama>

Fetch brings the remote branch, in your case that of your partner and stores it within <remoto>/<rama>

Pull is a combination of fetch + merge When you do the fetch you can do checkout to that branch within the remote without mixing it with a local one and then doing merge . Another quick option would also be to create a branch locally, do checkout to that branch and then pull the remote branch.

The problem with pull as expressed in your question, is that it makes both the fetch and a% automatic% of that branch to the branch where it is currently located.

For your specific case, you would do:

git fetch feature validateEmail

Then you enter that remote branch with:

git checkout feature/validateEmail

And you make the changes you need to then do merge with master or with any other branch.

    
answered by 02.12.2015 / 03:09
source
5

You should do a fetch first

git fetch <remote> <branchremoto>:<branchlocal> 
git checkout <branchlocal>

If your remote is origin:

git fetch origin feature/validateEmail:validateEmail
git checkout validateEmail

Documentation of git-fetch

If what you want to do is in a clone of the repository, you would have to add the repository as remote:

git remote add companiero https://github.com/user/repo.git
    
answered by 02.12.2015 в 03:06