Hi.
Is it possible to find the origin of a branch? (the remote repository that this branch was cloned and checked out from)
Thanks Dotan
threads / discuss / 19818
Subject: How can i find the origin of a branch?
Hi.
Is it possible to find the origin of a branch? (the remote repository that this branch was cloned and checked out from)
Thanks Dotan
Re: How can i find the origin of a branch?
ext Dotan Barak wrote:
> Hi. > > Is it possible to find the origin of a branch? > (the remote repository that this branch was cloned and checked out from)
git config -l
Assuming you're on the master branch, branch.master.remote and branch.master.merge will tell you which remote and which branch you are tracking. Assuming that the remote is origin, you can check remote.origin.url to see the URL of the repo.
-- Kristian
Re: How can i find the origin of a branch?
Thank you very much for a quick and exact answer :)
Dotan
On Mon, Jun 15, 2009 at 2:57 PM, Kristian Amlie<kristian.amlie@nokia.com> wrote:
> ext Dotan Barak wrote: >> Hi. >> >> Is it possible to find the origin of a branch? >> (the remote repository that this branch was cloned and checked out from) > > git config -l > > Assuming you're on the master branch, branch.master.remote and > branch.master.merge will tell you which remote and which branch you are > tracking. Assuming that the remote is origin, you can check > remote.origin.url to see the URL of the repo. > > -- > Kristian >
Re: How can i find the origin of a branch?
Thanks, your suggestion helped, but there is one problem:
I noticed that if there is only one branch, the entry branch.<branch_name>.merge doesn't exist. Even if there is more than one remote URLs.
Dotan
On Mon, Jun 15, 2009 at 3:03 PM, Dotan Barak<dotanba@gmail.com> wrote:
> Thank you very much for a quick and exact answer > :) > > Dotan > > > On Mon, Jun 15, 2009 at 2:57 PM, Kristian Amlie<kristian.amlie@nokia.com> wrote: >> ext Dotan Barak wrote: >>> Hi. >>> >>> Is it possible to find the origin of a branch? >>> (the remote repository that this branch was cloned and checked out from) >> >> git config -l >> >> Assuming you're on the master branch, branch.master.remote and >> branch.master.merge will tell you which remote and which branch you are >> tracking. Assuming that the remote is origin, you can check >> remote.origin.url to see the URL of the repo. >> >> -- >> Kristian >> >
Re: How can i find the origin of a branch?
2009/6/15 Kristian Amlie <kristian.amlie@nokia.com>:
> ext Dotan Barak wrote: >> >> Is it possible to find the origin of a branch? >> (the remote repository that this branch was cloned and checked out from) > > git config -l > > Assuming you're on the master branch, branch.master.remote and > branch.master.merge will tell you which remote and which branch you are > tracking. Assuming that the remote is origin, you can check > remote.origin.url to see the URL of the repo.
Except when it is just happen to have the same name. IOW, it is a BIG oversimplification.
Re: How can i find the origin of a branch?
ext Alex Riesen wrote:
> 2009/6/15 Kristian Amlie <kristian.amlie@nokia.com>: >> ext Dotan Barak wrote: >>> Is it possible to find the origin of a branch? >>> (the remote repository that this branch was cloned and checked out from) >> git config -l >> >> Assuming you're on the master branch, branch.master.remote and >> branch.master.merge will tell you which remote and which branch you are >> tracking. Assuming that the remote is origin, you can check >> remote.origin.url to see the URL of the repo. > > Except when it is just happen to have the same name. > IOW, it is a BIG oversimplification.
Probably, but why make the simple case overcomplicated? It should give you the answer in 90% of the cases.
-- Kristian
Re: How can i find the origin of a branch?
2009/6/15 Dotan Barak <dotanba@gmail.com>:
> Is it possible to find the origin of a branch? > (the remote repository that this branch was cloned and checked out from)
Look for a repository which has the smallest count of commits in common with the branch.
You can use git merge-base to find all the commits which could possible be the point of divergence (aka "merge base"). Then you can find all the remote branches which have the "merge bases" (git branch --contains <base>). Any of that remote branches could have been the origin of your local branch.
You'll seldom (if ever again) need that, I think.
P.S. You don't clone branches. Not as such. You clone repositories, which have the commits, which a branch (as in "reference") can point to.