Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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.

like image 965
startupsmith Avatar asked Jan 22 '26 01:01

startupsmith


2 Answers

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.

like image 81
Greg Hewgill Avatar answered Jan 25 '26 02:01

Greg Hewgill


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.

like image 37
Nic Avatar answered Jan 25 '26 01:01

Nic