8

I am trying to come to terms with Git as I recently started using it (long time Subversion user) and I cannot find a way to clone a remote branch with TortoiseGit.

I have created a local branch which I pushed to GitHub, but when I try to clone (checkout) this remote branch I cannot find any way to do it.

How can I do it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Thomas
  • 4,641
  • 13
  • 44
  • 67
  • 2
    You don't normally clone a remote branch, you clone the entire repository. Once it's cloned, you can checkout out that branch. Also, although you specifically asked about Tortoise, if you don't mind dropping to command line, you can execute [this command](http://stackoverflow.com/a/9920956/164966). – Roman Oct 03 '12 at 13:52
  • git clone -b branch_name. Currently (v1.7.13), no such function provided by TortoiseGit. – linquize Oct 04 '12 at 02:32

5 Answers5

17

As stated by linquize, this functionality isn't directly provided by TortoiseGit. If you really want to use it though, you can:

  • Clone the repository that the branch belongs to (right-click menu -> Git Clone...). This will also checkout the working copy created by clone to HEAD

TortoiseGit clone window

  • Switch the working copy from HEAD to the desired branch/tag (right-click menu -> TortoiseGit -> Switch/Checkout)

TortoiseGit switch window

This will take a bit longer than from the command line, because the initial clone command implies a checkout to head, which you then have to switch back to the branch/tag you want.

sbell
  • 457
  • 6
  • 13
  • 11
    Note that the current version of TortoiseGit does have a "branch" input on in the clone dialog - entering the name of the remove branch in this input will check it out directly. – mindplay.dk Jan 15 '13 at 03:21
13

It's available in Git clone window: enter image description here

Yue Lin Ho
  • 2,945
  • 26
  • 36
Vishwajeet
  • 311
  • 3
  • 5
9

(This is as of TortoiseGit v1.8.3.0.)

Do a "Git -> Git Sync" first in the TortoiseGit context menu. (Note: you may have to hold Shift down as you right click, depending on how you have Git Sync set to show up in your context menu.)

There will be a button in there at the bottom left called "Remote Update". Do that, and it will pull down all of the new remote branches that are not present in your local repository.

Remote Update

After that, you should be able to do "Git -> Git Checkout" as normal, and the branch you want will show up in the list.

I should note that this same procedure can be used to inform TortoiseGit about new branches that have been created in the remote repository, whether you originally created them or not.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
metaforge
  • 911
  • 10
  • 11
1

Unfortunately, the current TortoiseGit (TortoiseGit 1.7.13.0) can not clone a specific branch. You may ask a feature request.

The workaround:

  1. Use a manual Git command, e.g.: git clone --recursive --branch 2.x-1.0
  2. Use another Git GUI, e.g. SmartGit

Another way is to clone all branches then delete unwanted branches, but even this is not a good solution especially if you have many branches with many tags (and different file-names), but this is the workaround so far until TortoiseGit provides it. I choose to clone a branch manually using the command line. This question only happened for Windows users because the Git version of Linux already provides the --branch options.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Wendy William
  • 305
  • 2
  • 4
  • "Another way is clone all branches" - how? When leaving the *branch* checkbox in TortoiseGit 2.3.0.0's *Clone* window unchecked, I am still just getting the *master* branch locally, with all other branches just being available as remote branches. – O. R. Mapper Nov 24 '16 at 22:27
0

Update regarding this:

If you only need a specific branch, you can SVN checkout it directly, nowadays. Copy the tree URL of the branch, i.e. https://github.com/USERNAME/REPONAME/tree/BRANCHNAME and replace tree with branches, so you get https://github.com/USERNAME/REPONAME/branches/BRANCHNAME.

This URL can be used to checkout the specific branch.

Martin Braun
  • 10,906
  • 9
  • 64
  • 105