5

I'd like to add a copy of a remote branch (origin/featureX) to my local repository.

Therefore I generated a local branch featureX and set it to track the given remote branch:

git branch featureX
git branch -u origin/featureX featureX
# Branch featureX set up to track remote branch featureX from origin.

Now is there a way to show this connection? I tried e.g. git branch -av, but no connection between featureX and remotes/origin/featureX are shown.

Edward
  • 4,453
  • 8
  • 44
  • 82

3 Answers3

11

You need to be more verbose git branch -vv, this is documented but not obvious.

-v
-vv
--verbose
When in list mode, show sha1 and commit subject line for each head, along with relationship to upstream branch (if any). If given twice, print the name of the upstream branch, as well (see also git remote show ).

Andreas Wederbrand
  • 38,065
  • 11
  • 68
  • 78
4

To see the linkage easily, double the -v option:

$ git branch -v
* master   b9a3e01 [ahead 3]
$ git branch -vv
* master   b9a3e01 [origin/master: ahead 3]

See VonC's answer for a more convenient way to get these things started, in most cases.

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775
2

Instead of git branch, try a git checkout featureX.
Since there is an origin/featureX branch, that local branch would be linked automatically to the remote tracking one.

Delete your branch first, and recreate it:

git branch -d featureX
git checkout featureX

From git checkout:

If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to

$ git checkout -b <branch> --track <remote>/<branch>
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250