# Clone a repo and checkout a specifc remote branch

3 messages from 2009-03-07 to 2009-03-07. Participants: Paolo Ciarrocchi, Patrick Notz.
Thread: https://gitlist.dev/t/18188

## Paolo Ciarrocchi, 2009-03-07 11:42

Subject: Clone a repo and checkout a specifc remote branch
Message-ID: <4d8e3fd30903070342q584315cjcd059dcfe558dcfd@mail.gmail.com>
URL: https://gitlist.dev/e/4d8e3fd30903070342q584315cjcd059dcfe558dcfd%40mail.gmail.com

```
Hi list,
I've got a few questions from a friend that used git for the first
time, I answered to all of them but the following.

Scenario:
He knows the URl of a git repository which contains a few branches. He
is interested only to a single specific branch.
He expected to manage to clone the specific remote branch with a
single command, instead he had to learn the following procedure:

$ git clone git://uri_of_the_repo localdir
$ cd localdir
$ git branch
* master
# OK, so now he cloned the whole repository and checked out the master branch
$ git checkout mybranch origin/coolbranch

Wouldn't be an improvement to let the user to specify which remote
branch he want to be checked out after a clone?
Something like:
$ git clone git://uri_of_the_repo:coolbranch localdir
to get a clone of the whole repository and to check out the
origin/coolbranch remote branch?

I quickly discussed this scenario on the #git channel and a user
suggested to use the following procedure:
$ git init
$ git fetch git://uri_of_the_repo coolbranch
which was new to me, I tried it as follow:
$ git fetch git://git.kernel.org/pub/scm/git/git.git man
remote: Counting objects: 7319, done.←[K
remote: Compressing objects: 100% (1536/1536), done.←[K
remote: Total 7319 (delta 5640), reused 7290 (delta 5625)←[K
Receiving objects: 100% (7319/7319), 1.40 MiB | 110 KiB/s, done.
Resolving deltas: 100% (5640/5640), done.
From git://git.kernel.org/pub/scm/git/git
 * branch            man        -> FETCH_HEAD

but now I don't understand how to checkout the branch :-/

Ciao,
-- 
Paolo
http://paolo.ciarrocchi.googlepages.com/
http://mypage.vodafone.it/

```

## Patrick Notz, 2009-03-07 18:53

Subject: Re: Clone a repo and checkout a specifc remote branch
Message-ID: <1cd1989b0903071053l3f7aa35bu8e8e6b7e56cfc34f@mail.gmail.com>
URL: https://gitlist.dev/e/1cd1989b0903071053l3f7aa35bu8e8e6b7e56cfc34f%40mail.gmail.com
In-Reply-To: <4d8e3fd30903070342q584315cjcd059dcfe558dcfd@mail.gmail.com>

```
On Sat, Mar 7, 2009 at 4:42 AM, Paolo Ciarrocchi
<paolo.ciarrocchi@gmail.com> wrote:
> Hi list,
> I've got a few questions from a friend that used git for the first
> time, I answered to all of them but the following.
>
> Scenario:
> He knows the URl of a git repository which contains a few branches. He
> is interested only to a single specific branch.
> He expected to manage to clone the specific remote branch with a
> single command, instead he had to learn the following procedure:
>
> $ git clone git://uri_of_the_repo localdir
> $ cd localdir
> $ git branch
> * master
> # OK, so now he cloned the whole repository and checked out the master branch
> $ git checkout mybranch origin/coolbranch
>
> Wouldn't be an improvement to let the user to specify which remote
> branch he want to be checked out after a clone?
> Something like:
> $ git clone git://uri_of_the_repo:coolbranch localdir
> to get a clone of the whole repository and to check out the
> origin/coolbranch remote branch?
>

Here's a link to a recent thread on this topic (that started with a
proposed patch)

http://thread.gmane.org/gmane.comp.version-control.git/111967

You can read the arguments there.  Johannes Schindelin noted that the
normal way to do this is like this:

<quote>
Besides, the common way to check out something different than the remote's
HEAD is like this:

$ git clone -n $URL
$ cd $DIR
$ git checkout -t origin/$BRANCH
</quote>


> I quickly discussed this scenario on the #git channel and a user
> suggested to use the following procedure:
> $ git init
> $ git fetch git://uri_of_the_repo coolbranch
> which was new to me, I tried it as follow:
> $ git fetch git://git.kernel.org/pub/scm/git/git.git man
> remote: Counting objects: 7319, done.←[K
> remote: Compressing objects: 100% (1536/1536), done.←[K
> remote: Total 7319 (delta 5640), reused 7290 (delta 5625)←[K
> Receiving objects: 100% (7319/7319), 1.40 MiB | 110 KiB/s, done.
> Resolving deltas: 100% (5640/5640), done.
> From git://git.kernel.org/pub/scm/git/git
>  * branch            man        -> FETCH_HEAD
>
> but now I don't understand how to checkout the branch :-/
>
> Ciao,
> --
> Paolo
> http://paolo.ciarrocchi.googlepages.com/
> http://mypage.vodafone.it/
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

```

## Paolo Ciarrocchi, 2009-03-07 23:25

Subject: Re: Clone a repo and checkout a specifc remote branch
Message-ID: <4d8e3fd30903071525g27960764rbc1cee77e4334a6e@mail.gmail.com>
URL: https://gitlist.dev/e/4d8e3fd30903071525g27960764rbc1cee77e4334a6e%40mail.gmail.com
In-Reply-To: <1cd1989b0903071053l3f7aa35bu8e8e6b7e56cfc34f@mail.gmail.com>

```
On 3/7/09, Patrick Notz <patnotz@gmail.com> wrote:

>> Something like:
>> $ git clone git://uri_of_the_repo:coolbranch localdir
>> to get a clone of the whole repository and to check out the
>> origin/coolbranch remote branch?
>>
>
> Here's a link to a recent thread on this topic (that started with a
> proposed patch)
>
> http://thread.gmane.org/gmane.comp.version-control.git/111967
>
> You can read the arguments there.  Johannes Schindelin noted that the
> normal way to do this is like this:
>
> <quote>
> Besides, the common way to check out something different than the remote's
> HEAD is like this:
>
> $ git clone -n $URL
> $ cd $DIR
> $ git checkout -t origin/$BRANCH
> </quote>

Thank you, very appreciated, I missed that discussion.

I'll add my comments to that thread.

Regards,
-- 
Paolo
http://paolo.ciarrocchi.googlepages.com/
http://mypage.vodafone.it/

```
