startupsmith
startupsmith

Reputation: 5764

Git get remote branch locally that didn't previously exist?

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.

Upvotes: 3

Views: 836

Answers (3)

First Zero
First Zero

Reputation: 22376

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

Upvotes: 0

Greg Hewgill
Greg Hewgill

Reputation: 994659

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.

Upvotes: 5

Nic
Nic

Reputation: 13761

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.

Upvotes: 1

Related Questions