Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pull down a remote branch?

Tags:

git

git-pull

I've been searching for a half hour for how to do pull a remote branch, and cannot figure it out.

My remote git repository has a branch called frontend. When I run git pull origin frontend I get the following output:

* branch             frontend     -> FETCH-HEAD
Already up-to-date.

When I run git branch, I get the following:

*master

Why isn't frontend in the list returned by git branch?

If it helps at all, when I run git branch -v -a, one of the returned branches is remotes/origins/frontend

Thanks in advance!!

like image 874
Christopher Shroba Avatar asked Nov 08 '14 02:11

Christopher Shroba


3 Answers

git pull origin frontend is equivalent to get fetch origin frontend and get merge frontend. Note that this merges the remote branch named frontend to the current local branch, in your case master. If you want a local branch with the same name as the remote branch, you should create it first. One way to do this is

git checkout -b frontend
git pull origin frontend

You should read up on the differences between a local branch and a remote tracking branch.

Alternatively, you can manually fetch then checkout the branch:

git fetch origin
git checkout frontend

If you don't already have a branch with the name frontend, git will find the remote tracking branch and automatically create a local branch at the same commit.

like image 97
Code-Apprentice Avatar answered Sep 28 '22 08:09

Code-Apprentice


You need to create local branch as well. Since there already is a remote branch in your repo, just type:

git checkout frontend

git will autocratically create local branch and set upstream branch as well.

like image 36
BroiSatse Avatar answered Sep 28 '22 08:09

BroiSatse


Why isn't frontend in the list returned by git branch?

Because you don't have a local branch named "frontend".

There are a number of git config settings that might factor in here but one thing you can do if you want to create a local branch named "frontend" which tracks the remote branch of the same name is something like the following:

git branch --track frontend origin/frontend

I hope that helps.

like image 24
Jeff Scott Brown Avatar answered Sep 28 '22 08:09

Jeff Scott Brown