threads / discuss / 30492

how to clone/checkout branch/tag vesion from GIT repository

Subject: how to clone/checkout branch/tag vesion from GIT repository

## tl;dr

9 messages between May 10, 2012 and May 14, 2012.

replies: 8people: 3as markdown or json

supadhyay· May 10, 2012, 13:39 UTC · lore
Hi All,

I try to use below command to do clone from particular branch/version number. I used below command...

$ git clone -b br6-1-0 ssh://gitolite@myservername/testrep Cloning into 'testrep'... remote: Counting objects: 19536, done. remote: Compressing objects: 100% (5850/5850), done. remote: Total 19536 (delta 13869), reused 18869 (delta 13202) Receiving objects: 100% (19536/19536), 61.44 MiB | 17 KiB/s, done. Resolving deltas: 100% (13869/13869), done. warning: Remote branch br6-0 not found in upstream origin, using HEAD instead

End user query is - they want the clone from particular branch which is separate from Head so I run above commmand. Can any one please help me how to resolve this?

Is there any way to findout how many branches are available in my GIT repository.

Thanks in advance...

-- View this message in context: http://git.661346.n2.nabble.com/how-to-clone-checkout-branch-tag-vesion-from-GIT-repository-tp7546744.html Sent from the git mailing list archive at Nabble.com.

Jeff King· May 10, 2012, 13:56 UTC · re: supadhyay · lore

Re: how to clone/checkout branch/tag vesion from GIT repository

On Thu, May 10, 2012 at 06:39:47AM -0700, supadhyay wrote:
Show 12 quoted lines
> I try to use below command to do clone from particular branch/version
> number. I used below command...
> 
> $ git clone -b br6-1-0 ssh://gitolite@myservername/testrep
> Cloning into 'testrep'...
> remote: Counting objects: 19536, done.
> remote: Compressing objects: 100% (5850/5850), done.
> remote: Total 19536 (delta 13869), reused 18869 (delta 13202)
> Receiving objects: 100% (19536/19536), 61.44 MiB | 17 KiB/s, done.
> Resolving deltas: 100% (13869/13869), done.
> warning: Remote branch br6-0 not found in upstream origin, using HEAD
> instead

Side note: if I repeat your experiment, I get "br6-1-0" in the error message (i.e., what was on the command line). Is this just a cut and paste mistake in reporting the error, or is that actually what you see?

Assuming that is the case, the problem is that git versions before v1.7.10 did not expect a tag name with the "-b" switch. Either upgrade to git v1.7.10, or clone and manually switch to the tag, like this:

  $ git clone ssh://.../testrep
  $ cd testrep
  $ git checkout br6-1-0

Note that if you are planning on doing work based on the tag, you probably want to create a new branch, like:

  $ git checkout -b my-work br6-1-0
> Is there any way to findout how many branches are available in my GIT
> repository.

In your local clone, or on the remote? In the local clone, you can use "git branch" to see local branches, or "git branch -a" to see branches copied from the remote. To see what is available on the remote, try "git ls-remote ssh://...".

-Peff
Suchi Upadhyay· May 10, 2012, 14:19 UTC · re: Jeff King · lore

RE: how to clone/checkout branch/tag vesion from GIT repository

Hi Jeff,
Thanks for your prompt reply.
Please see my reply below:
1- Side note: if I repeat your experiment, I get "br6-1-0" in the error message (i.e., what was on the command line). Is this just a cut and paste mistake in reporting the error, or is that actually what you see?
Suchi - yes my mistake in cut & paste. Branch name is br6-1-0

2- for branch: $ git checkout br6-1-0

Suchi - As per my understanding with GIT this command will create a new branch in my repository..for ex. If I run "git checkout suchi" then it will create suchi as a new branch.
2.1 Note that if you are planning on doing work based on the tag, you probably want to create a new branch, like:
  $ git checkout -b my-work br6-1-0
Suchi - Yes, I have this branch br6-1-0 and data is associated there, this branch is different from head. For end user perspective I just want to make sure that my data is there or not so I performed clone but not working (Again not sure which command I have to use).
Please note that  - branch br6-1-0 created in CVS and then our source code migrated to Git. But in migration output I can see the br6-1-0 picked up for copying ...
3- In your local clone, or on the remote? In the local clone, you can use "git branch" to see local branches, or "git branch -a" to see branches copied from the remote. To see what is available on the remote, try "git ls-remote ssh://...".
Suchi - I want a branch list from remote. I have run your suggested command  but it shows only tag list and no branch.

Thanks, Suchi

-----Original Message-----
From: Jeff King [mailto:peff@peff.net] 
Sent: Thursday, May 10, 2012 7:26 PM
To: Suchi Upadhyay
Cc: git@vger.kernel.org
Subject: Re: how to clone/checkout branch/tag vesion from GIT repository
On Thu, May 10, 2012 at 06:39:47AM -0700, supadhyay wrote:
Show 12 quoted lines
> I try to use below command to do clone from particular branch/version 
> number. I used below command...
> 
> $ git clone -b br6-1-0 ssh://gitolite@myservername/testrep
> Cloning into 'testrep'...
> remote: Counting objects: 19536, done.
> remote: Compressing objects: 100% (5850/5850), done.
> remote: Total 19536 (delta 13869), reused 18869 (delta 13202) 
> Receiving objects: 100% (19536/19536), 61.44 MiB | 17 KiB/s, done.
> Resolving deltas: 100% (13869/13869), done.
> warning: Remote branch br6-0 not found in upstream origin, using HEAD 
> instead
Side note: if I repeat your experiment, I get "br6-1-0" in the error message (i.e., what was on the command line). Is this just a cut and paste mistake in reporting the error, or is that actually what you see?

Assuming that is the case, the problem is that git versions before v1.7.10 did not expect a tag name with the "-b" switch. Either upgrade to git v1.7.10, or clone and manually switch to the tag, like this:

  $ git clone ssh://.../testrep
  $ cd testrep
  $ git checkout br6-1-0
Note that if you are planning on doing work based on the tag, you probably want to create a new branch, like:
  $ git checkout -b my-work br6-1-0
> Is there any way to findout how many branches are available in my GIT 
> repository.
In your local clone, or on the remote? In the local clone, you can use "git branch" to see local branches, or "git branch -a" to see branches copied from the remote. To see what is available on the remote, try "git ls-remote ssh://...".
-Peff
Jeff King· May 10, 2012, 14:39 UTC · re: Suchi Upadhyay · lore

Re: how to clone/checkout branch/tag vesion from GIT repository

On Thu, May 10, 2012 at 10:19:12AM -0400, Suchi Upadhyay wrote:
Show 6 quoted lines
> 2- for branch:
> $ git checkout br6-1-0
> 
> Suchi - As per my understanding with GIT this command will create a
> new branch in my repository..for ex. If I run "git checkout suchi"
> then it will create suchi as a new branch.
Not exactly. It will do one of:
  1. If a local branch named br6-1-0 exists, it will be checked out.
  2. If a tag named br6-1-0 exists, then you will be put in a "detached
     HEAD" state, starting at the tag. See the "detached HEAD" section
     of "git help checkout" for details.
  3. If a remote branch named br6-1-0 exists, a local branch of the same
     name will be created, starting at the same spot.
  4. Otherwise, it is an error.
Show 6 quoted lines
> Please note that  - branch br6-1-0 created in CVS and then our source
> code migrated to Git. But in migration output I can see the br6-1-0
> picked up for copying ...
> [...]
> Suchi - I want a branch list from remote. I have run your suggested
> command  but it shows only tag list and no branch.
>From the message you are seeing from "git clone -b", and from the output

of "ls-remote", it sounds like br6-1-0 really is a tag in git, not a branch. Since you have said it is coming from CVS, I suspect this is an artifact of the CVS->git conversion. And if that is not the desired outcome, you should look into your conversion process (there are several tools available; if you used git-cvsimport, it is generally considered to to be the least accurate, and you might try cvs2git).

-Peff
supadhyay· May 11, 2012, 12:45 UTC · re: Jeff King · lore

Re: how to clone/checkout branch/tag vesion from GIT repository

Hi Jeff,
Thanks for your reply.

branch - br6-1-0 is already exists on remote. I have my few data which are associated on this branch and I want to get that specific data from br6-1-0.

I did cvs2git and its working fine without any issue. 

Also I can see the list of branches when I run "git branch -r" on my GITserver through "git" user. But after did this migration I do clone from git to gitolite on the same server (to manage with user functionality). Now, after cloning to gitolite if I run "git branch -r" it shows only master.

I follow belwo step 1- cvs 2 git >> I can see list of branches here 2- git 2 gitolite >> I can not see any branch except master.

Thanks, Suchi

-- View this message in context: http://git.661346.n2.nabble.com/how-to-clone-checkout-branch-tag-vesion-from-GIT-repository-tp7546744p7550370.html Sent from the git mailing list archive at Nabble.com.

Jeff King· May 11, 2012, 17:22 UTC · re: supadhyay · lore

Re: how to clone/checkout branch/tag vesion from GIT repository

On Fri, May 11, 2012 at 05:45:19AM -0700, supadhyay wrote:
Show 13 quoted lines
> branch - br6-1-0 is already exists on remote. I have my few data which are
> associated on this branch and I want to get that specific data from br6-1-0.
> 
> I did cvs2git and its working fine without any issue. 
> 
> Also I can see the  list of branches when I run "git branch -r"  on my
> GITserver through "git" user. But after did this migration I do clone from
> git to gitolite on the same server (to manage with user functionality). Now,
> after cloning to gitolite if I run "git branch -r" it shows only master.
> 
> I follow belwo step
> 1- cvs 2 git  >> I can see list of branches here 
> 2- git 2 gitolite  >> I can not see any branch except master.

How did you do the clone? A regular "clone" will clone only local branches of the remote repository (so if B fetches from A, and C fetches from B, C will not bother with A's branches).

If you are trying to clone the repository to act as a server repository in gitolite, I think you would want to use "git clone --mirror". This will omit the working tree (which you should not need for the server end), and will fetch all branches (exactly mirroring the state of the original repository).

-Peff
supadhyay· May 12, 2012, 10:26 UTC · re: Jeff King · lore

Re: how to clone/checkout branch/tag vesion from GIT repository

Hi Jeff,

I follow below steps to do clone from git to gitolite (I did the cvs2git migration of individual repository successfully).

1- login to gitolite user and add repository entry in to gitolite.conf file and do add,commit and push. In push operation output it shows the path of the repository.

2- from gitolite_home I run below command git clone ssh://git@mygitserver.com/ora/data/test.git (tis is do the clone of my repository so I can see the actual data inside the repository)

3- then cd to test and push all the changes ; git push --all gitolite@mygitserver.com:test

4- push all tags also; git push --tags gitolite@mygitserver.com:test

5- lastly do the clone of test repository to my workstation using tortoise git tool; ssh://gitolite@mygitserver/test

Please guide me if anything missing or needs to add.
Thanks.

-- View this message in context: http://git.661346.n2.nabble.com/how-to-clone-checkout-branch-tag-vesion-from-GIT-repository-tp7546744p7553161.html Sent from the git mailing list archive at Nabble.com.

supadhyay· May 14, 2012, 06:18 UTC · re: supadhyay · lore

Re: how to clone/checkout branch/tag vesion from GIT repository

Hi Jeff,
Did you find anything missing/wrong approach in the above steps?
Thanks...

-- View this message in context: http://git.661346.n2.nabble.com/how-to-clone-checkout-branch-tag-vesion-from-GIT-repository-tp7546744p7555785.html Sent from the git mailing list archive at Nabble.com.

Jeff King· May 14, 2012, 17:33 UTC · re: supadhyay · lore

Re: how to clone/checkout branch/tag vesion from GIT repository

On Sat, May 12, 2012 at 03:26:32AM -0700, supadhyay wrote:
> 2- from gitolite_home I run below command
> git clone ssh://git@mygitserver.com/ora/data/test.git
> (tis is do the clone of my repository so I can see the actual data inside
> the repository)

As I mentioned before, this should probably be a --mirror clone to get all of the remote branches, and to create a bare repository. I don't use gitolite, so perhaps there is some need I don't know about for it to have a working tree. But in general, I would think having a non-bare repository would be a problem here, as it would prevent pushes to the checked-out branch (but again, maybe there is some gitolite-specific thing I am missing).

-Peff

← back to recent threads