27

I've been working on the master branch in my Git repository for a while. It's hosted on GitHub and cloned on two of my computers. Now I started a new branch on one computer and pushed it to GitHub. Now they know both branches, but the other computer still only knows about the master branch, not the feature branch.

When I try to pull the feature branch from GitHub, Git will merge it into my master, which is not what I want.

How can I download the feature branch from GitHub into my local repository and end up having the two branches and no merge? I'm going to merge them when it's ready, not now.

If possible, I'm interested in what to do with TortoiseGit.

ygoe
  • 18,655
  • 23
  • 113
  • 210
  • "Git will merge it into my master" - if it's doing that, then something weird is happening. – Oliver Charlesworth May 24 '14 at 19:28
  • Duplicate of [What's the difference between 'git pull' and 'git fetch'?](http://stackoverflow.com/questions/292357/whats-the-difference-between-git-pull-and-git-fetch) –  May 24 '14 at 20:26
  • 3
    @Cupcake: This question can only be a duplicate of that *after* you know the answer to the question. It was not obvious to me that I need `fetch` so I could not find the other question. – ygoe May 25 '14 at 05:52

2 Answers2

35

You can do git fetch origin on the command line. This will update your local copy so that it knows about the new branch. Then, if you want to checkout the new branch, simply git checkout BRANCHNAME should track the remote.

brock
  • 2,302
  • 7
  • 27
  • 30
  • Thank you, your answers were equally helpful and I have to decide on one to accept. About TortoiseGit: I needed to use the Fetch command from the context menu. That created the remote branch that I could then switch to. Using the Fetch command from the Sync dialog did not do this because it added the master branch explicitly to the command line. – ygoe May 24 '14 at 19:46
17

A git fetch wouldn't merge anything:

git fetch
git checkout -b yourSecondBranch origin/yourSecondBranch 
# or simpler, since git 1.6+:
git checkout yourSecondBranch

(Here I fetch by default the remote 'origin', which should reference the GitHub repo)

See more at "git checkout remote branch"

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250