0

I have seen few posts saying that running

git branch -lvv

will show all your local branches and beside them, the remote branches your local branches are based on. But I do not see that happening.

I am using git version 2.7.1.windows.2:

me@ME-PC BLAH64 /c/code/myproj (BRANCH-10)
$ git --version
git version 2.7.1.windows.2

And here is what I get when I issue:

me@ME-PC BLAH64 /c/code/myproj (BRANCH-10)
$ git branch -lvv
* BRANCH-10        xxxxxxx some comment
  BRANCH-7         xxxxxxx some comment
  BRANCH-12        xxxxxxx some comment
  dev-branch       xxxxxxx [origin/master] some comment
  dev-branch-c     xxxxxxx some comment

xxxxxxx above are some strange looking numbers such as 05317bba or similar.

How do I see all mine local branches and the remote branches these local branches are based on? i.e. how do I know what remote branch is my local BRANCH-12 based on?

So, I am not looking for ALL branches but for my local branches and their respective remote branches.

pixel
  • 9,653
  • 16
  • 82
  • 149
  • 1
    Possible duplicate of [how do I get git to show me which branches are tracking what?](http://stackoverflow.com/questions/4950725/how-do-i-get-git-to-show-me-which-branches-are-tracking-what) – kan Apr 11 '16 at 19:46
  • 2
    If your git is not too ancient (yours is pretty recent) and `git branch -vv` does not show an upstream (as your output does not), that means your local branches do not have upstreams set. See http://stackoverflow.com/q/520650/1256452 – torek Apr 11 '16 at 20:28
  • @torek Thanks. I actually updated my question. I see branch in square brackets but that still does not answer my question. Check the update please and thank you – pixel Apr 11 '16 at 23:50
  • 1
    Not sure how you'd go about it via the command line but you can visualize the history using gitk. e.g. to view the history for local branch1, you'd use `gitk branch1`. All your tags, local branches, remote branches in its history are shown with coloured tags. You can see an example of the output in [this stackoverflow answer](http://stackoverflow.com/questions/1838873/visualizing-branch-topology-in-git/18287669#18287669). – Tone Apr 12 '16 at 01:10
  • 1
    OK, now you're apparently asking a different question: rather than "what is the upstream for each local branch, you want to know "what is ..." where the "..." part is not well defined. The phrase you used here is "based on", but what, precisely, do *you* mean by that? You will need to be precise! The reason this is tricky is that git's branches are not what most people seem to mostly think they mostly are, at first. Tone's comment above is a good starting point for thinking about this. – torek Apr 12 '16 at 01:22
  • @torek I see. Yes, I am new to git. I will try to explain. If I have remote branch called dev, then I will fetch that and merge it with my local dev branch (git fetch origin and git merge origin/dev). Then I issue git checkout -b branch1. Now assume I had more than one origin and more than one local branch. How do I find out that my branch1 is based on dev, branch2 on dev2, etc? Thanks – pixel Apr 12 '16 at 04:54
  • 1
    You're still using the phrase "based on". Suppose, for instance, that you have two remotes `alice` and `bob`. Suppose further that Bob started by cloning Alice's repo, and has made a commit on branch `bug123` and then shared it with Alice so she also has branch `bug123` with the *same* commit. You originally cloned Alice's repo and have `alice/bug123`, but then Alice gets a better job, deletes her repository entirely, and you fetch to update from `bob/bug123`. Which `bug123` are you "based on"? Does it matter, and if so, when? (Note that we said here that Bob and Alice were in sync.) – torek Apr 12 '16 at 06:49
  • 1
    If Bob and Alice were *not* in sync, it could matter, but if they were in sync, they had the same commits and it won't matter. In short, what you're looking for is kind of a mirage, due to the distributed nature of these repositories. (With that said, what you need to look at is the *commit graph*, using the commit IDs as unique identifiers, since, well, they *are* unique identifiers. That's how Alice and Bob, and now you, can share commits. Git doesn't track the *source* of a commit, only its contents, including parent IDs. The parent IDs form the commit graph, which is what matters.) – torek Apr 12 '16 at 06:52

1 Answers1

1

for my repos, git branch -vv will output something like you said, but in some cases it will output:

$ git branch -lvv
  branch1      3d52a6d some commit message 1
  branch2      36c34dc some commit message 2
  master       f476f37 [origin/master] some commit message 3

this means branch1 and branch2 are not present in remote (in my case they have already been deleted through Bitbucket)

pedrorijo91
  • 7,635
  • 9
  • 44
  • 82
  • In my case it is the same. Both branch1 and branch2 are my local branches. So, I am trying to find what remote branch are they based on. Let's say, I have 2 local and remote branches 'master' and 'master_new'. How do I know if my branch1 is based off 'master' and not 'master_new'? Thanks – pixel Apr 11 '16 at 23:46