0

The remote repository has two branches: master, develop.

Then, I checked my local branch by git branch , I notice I have only master branch, so I run command git fetch origin.

After this, when I run "git branch" again, I still see only master branch, why, isn't "git branch" supposed to list all local branches?

Does it mean the git fetch origin does not yet make the develop as my local branch? Then what git fetch actually doing?

(But I can see develop branch with git branch -r)

Leem
  • 17,220
  • 36
  • 109
  • 159

2 Answers2

3

Yes, when you run git fetch origin, git just updates all the so-called "remote-tracking branches" - those are the ones that look like origin/develop and origin/master that you can see in the output of git branch -r. You can't work directly on those branches, although in many other respects you can use them like your local branches. If you want to work on the develop branch, you have to create a local branch based on origin/develop. Using all of git's helpful "Do What I Mean" shortcuts, you can usually do this with just:

git checkout develop

... although the more explicit version of that command would be:

git checkout --track -b develop origin/develop
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
0

git fetch only fetches the git objects. Nothing more.

In your case, you have to create a local branch and set it to track a remote branch.

Anand
  • 10,310
  • 24
  • 90
  • 135