# How can i find the origin of a branch?

7 messages from 2009-06-15 to 2009-06-15. Participants: Dotan Barak, Alex Riesen, Kristian Amlie.
Thread: https://gitlist.dev/t/19818

## Dotan Barak, 2009-06-15 11:37

Subject: How can i find the origin of a branch?
Message-ID: <2f3bf9a60906150437v765c2cecva61307ae9cf0cec7@mail.gmail.com>
URL: https://gitlist.dev/e/2f3bf9a60906150437v765c2cecva61307ae9cf0cec7%40mail.gmail.com

```
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

```

## Kristian Amlie, 2009-06-15 11:57

Subject: Re: How can i find the origin of a branch?
Message-ID: <4A363741.9030604@nokia.com>
URL: https://gitlist.dev/e/4A363741.9030604%40nokia.com
In-Reply-To: <2f3bf9a60906150437v765c2cecva61307ae9cf0cec7@mail.gmail.com>

```
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

```

## Dotan Barak, 2009-06-15 12:03

Subject: Re: How can i find the origin of a branch?
Message-ID: <2f3bf9a60906150503p69e992b4m18bdc2cc842b933e@mail.gmail.com>
URL: https://gitlist.dev/e/2f3bf9a60906150503p69e992b4m18bdc2cc842b933e%40mail.gmail.com
In-Reply-To: <4A363741.9030604@nokia.com>

```
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
>

```

## Alex Riesen, 2009-06-15 12:07

Subject: Re: How can i find the origin of a branch?
Message-ID: <81b0412b0906150507r7b141951w7246b0abab9624e2@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0906150507r7b141951w7246b0abab9624e2%40mail.gmail.com
In-Reply-To: <2f3bf9a60906150437v765c2cecva61307ae9cf0cec7@mail.gmail.com>

```
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.

```

## Alex Riesen, 2009-06-15 12:48

Subject: Re: How can i find the origin of a branch?
Message-ID: <81b0412b0906150548m69abc1bax785a4743119804c6@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0906150548m69abc1bax785a4743119804c6%40mail.gmail.com
In-Reply-To: <4A363741.9030604@nokia.com>

```
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.

```

## Kristian Amlie, 2009-06-15 13:10

Subject: Re: How can i find the origin of a branch?
Message-ID: <4A36484A.3040207@nokia.com>
URL: https://gitlist.dev/e/4A36484A.3040207%40nokia.com
In-Reply-To: <81b0412b0906150548m69abc1bax785a4743119804c6@mail.gmail.com>

```
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

```

## Dotan Barak, 2009-06-15 13:34

Subject: Re: How can i find the origin of a branch?
Message-ID: <2f3bf9a60906150634p18e67e71q6e5e7cbb8df1d8c4@mail.gmail.com>
URL: https://gitlist.dev/e/2f3bf9a60906150634p18e67e71q6e5e7cbb8df1d8c4%40mail.gmail.com
In-Reply-To: <2f3bf9a60906150503p69e992b4m18bdc2cc842b933e@mail.gmail.com>

```
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
>>
>

```
