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!!
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With