3

I am wanting to bring a newly added remote branch into my local repository without interfering with my local branches. Is this possible?

When I do:

git branch -a 

The new remote branch doesn't appear in the list. So if I try to fetch the origin/newremotebranch it says that it doesn't exist.

5
  • 1
    What if you just do git fetch origin? That should create new remote tracking branches for all existing remote branches. Commented Dec 22, 2011 at 4:26
  • I think I misunderstood what you were asking so I deleted my answer. Unfortunately, it looks like you were mid-comment when I deleted it! What was the output of the command, out of curiosity? Also, @GregHewgill's suggestion should work. Commented Dec 22, 2011 at 4:29
  • No yours did work. I had to do Greg Hewgills command first which updated the remote branches locally. Then I did your command and now it works. Commented Dec 22, 2011 at 4:31
  • Ah! Well, either of you should post an answer. Mine missed a step. Commented Dec 22, 2011 at 4:33
  • I posted an answer that should do the trick. Commented Dec 22, 2011 at 4:35

3 Answers 3

5

The following command will update your remote tracking branches:

git fetch origin 

This will create new remote tracking branches in your local repository for any remote branches that don't yet have one.

Sign up to request clarification or add additional context in comments.

Comments

1

You should be able to simply check out the remote branch:

git checkout -b new-branch-name origin/newremotebranch

Should start tracking, and you'll be able to fetch after that.

3 Comments

I tried that and it gives me: fatal "git checkout: updating paths is incompatible with switching branches. Did you intend to checkout 'origin/newbranchname' which can not be resolved as commit?"
As per the comments, git fetch origin should make this possible.
git fetch origin will definitely fix it. However, should you ever get a similar error after doing a git fetch, make sure you didn't make a typo. I've gotten that error before by typing "orgin"
0

You can even setup tracking. The commands - cf - Error when pull from remote branch

git branch --track my-other-branch origin/my-other branch git pull origin my-otherbranch 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.