1

all

I have downloaded source code from google android website following google's guide. My purpose is to create a local branch to track remote branch

take framework/media for example, you can see .git under this directory, but when you run

git branch

the output is

*no branch

I crate my local branch using

git checkout -b local

then I have the problem, how can I switch back to track remote branch, I cannot pull updated source code from google for this .git again. There is only one local branch.

I also tried

git remote

and get

aosp https://android.googlesource.com/platform/frameworks/base (fetch)

aosp https://android.googlesource.com/platform/frameworks/base (push)

git branch --track local aosp

but I get the error

fatal: Not a valid object name: aosp

Anybody can give me some advice and guide? thanks very much.

thisEric
  • 486
  • 7
  • 18
  • Clone remote branch first, then create a new local branch you can modify in. – Warpzit Mar 19 '12 at 09:01
  • If one of the answers presented below worked for your question, you should mark it as accepted by clicking the green outline of a checkmark next to it. – Amber Mar 20 '12 at 03:13

2 Answers2

2

You can use...

git branch --track local aosp/master

(The reason you're getting an error is because aosp is a remote, not a specific thing on that remote. aosp/master refers to the master branch on that remote, and thus can be tracked.)

Amber
  • 507,862
  • 82
  • 626
  • 550
1

As mentioned in "How do you make an existing git branch track a remote branch?"

As of Git 1.7.0:

 git branch --set-upstream local aosp/local

will work too.
Note that for git 1.8+, discussions are in progress in order to make aosp/local an argument of --set-upstream (instead of a separate parameter).

In order to make its usage unambiguous, and to allow it to be used w/o specifying the current branch, require it to take an argument like so:

(master)$ git branch --set-upstream=origin/master 
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250