2

I am learning about git. Issued the following:

git clone https://android.googlesource.com/kernel/goldfish.git

then cd to goldfish, and then issued:

git branch

to see the list of existing branches. But only the "master" branch appears, while on https://android.googlesource.com/kernel/goldfish/ many others are listed.

Now I should checkout the correct branch. This old question has an answer which suggests to issue

git checkout -t origin/android-goldfish-2.6.29 -b goldfish

Things may obviously have changed a lot since, so I need to understand if I have to checkout the "master" branch or if I am missing something. Also, I don't understand the need for the -t and -b options, and for the path.

In summary, should I issue

git checkout master

or anything else?

EDIT

Just had some feedback from #android-root: git branch lists local branches. To list the remote ones, use git branch -r. Now I have the correct list. In any case I'd like to know the necessity of the -t and -b options. The parameter after the -t option is not a path, is the name of the branch (it begins by origin/, it seems). But what is the "goldfish" parameter at the end? And shouldn't the branch name follow the -b parameter?

Community
  • 1
  • 1
Enrico
  • 325
  • 1
  • 2
  • 15

2 Answers2

1

The -b and -t options are being used to create a local branch called goldfish which tracks the remote branch called android-goldfish-2.6.29

You can do the same thing with the following:

$ git checkout android-goldfish-2.6.29

... the only difference being that your local branch will have the same name as the remote branch. This should work if you have exactly one remote with a branch named android-goldfish-2.6.29.

For more about the git checkout command, see: https://git-scm.com/docs/git-checkout#git-checkout-emgitcheckoutemltbranchgt

jsa
  • 1,050
  • 10
  • 22
  • Forgot the 'origin/' or is it unnecessary? – Enrico Mar 12 '17 at 22:09
  • Seems that without the -b option no local branch is created: `You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b ` – Enrico Mar 12 '17 at 22:24
  • From https://git-scm.com/docs/git-checkout#git-checkout-emgitcheckoutemltbranchgt `git checkout ` If is not found but there does exist a tracking branch in exactly one remote (call it ) with a matching name, treat as equivalent to `$ git checkout -b --track /` – jsa Mar 13 '17 at 12:02
  • Yes, I have seen that, but when I invoked `git checkout ` I got the message reported in my previous comment. Note that I included the 'origin/' in the branch name. – Enrico Mar 13 '17 at 13:36
  • You should not need to include `origin` in the branch name - simply `git checkout android-goldfish-2.6.29`. Does that work as expected? – jsa Mar 13 '17 at 15:38
  • Thank you for all the info. Since I already got the directory ready by using 'origin/', although I got that message, I'd prefer not to try again without 'origin/', at least for now. But I think that in that way the local branch would be created. For now it's enough to look around and try to understand how it works. – Enrico Mar 13 '17 at 17:30
0

You can use git branch -a to see all branches. -b is used to name the new branch. -t is used to setup tracking to the remote branch, so if you want to get android-goldfish-2.6.29 you have to use the command you post.

But if you want to get the newer version of goldfish you can use git checkout -t origin/android-goldfish-4.4-dev -b goldfish-4.4

X3Btel
  • 1,408
  • 1
  • 13
  • 21