IntelliJ IDEA git clone a specific branch
Asked Answered
L

4

14

I need to create a new project based on a specific git branch. I selected: File->new->Project from Version Control->Git however there are only 3 fields which result in cloning the master branch:

  • Git Repository URL
  • Parent Directory
  • Directory Name

However there is no option to submit the specific branch.

Is there anyway to clone a specific branch using Git in IntelliJ?

Lucero answered 24/4, 2017 at 13:50 Comment(2)
Once you've cloned the repo, just switch branches using the drop-down in the bottom right corner of the window.Bigot
You don't clone Git branches; you clone a repository, then check out the branch you need.Grandniece
M
14

You misunderstood Git. In Git as in any DVCS by default you clone the full repository including all branches. Only for the default branch of the cloned repository (most often this is master), there is a local branch created autmatically and checked out. But you still have all branches of the cloned repository present as remote tracking branches in your local repository. So just checkout the branch you want after you did the clone. If you clone with the commandline instead, you can give the clone command the branch that should be checked out after the clone automatically if different from the default branch, but IJ does not have an option for that apparently. But switching the branch after the cloning is easy.

Mossy answered 24/4, 2017 at 13:59 Comment(0)
S
12

As Vampire say, you have to clone all the git project, then change branch. You can change the branch pressing on bottom-right > Git:master > Remote Branches > chose your branch > Checkout as new local branch

Selfpossession answered 24/4, 2017 at 14:17 Comment(1)
BOTTOM RIGHT ! It was hiding (in plain site). I think I know why the question was posed. You don't get the "import as maven" or "import as gradle" voodoo when you change the branch at a later time.Mag
B
6

First you do checkout from master, once done go right side bottom corner, and Click on Git, popup will open , click on show more,it will populate all branches in remote Branches. ( better drag and maximize that box) . and select your required branch from Remote Branches and do check out. Automatically your selected branch will come as your project in intellij. Image of Inttelij Bottom Location

Select Show more Option

Do Check your required branch

Begone answered 27/7, 2018 at 7:5 Comment(0)
E
0

You can clone single branch by command line which explained here: How do I clone a specific Git branch But this is not the straight road to do that.

Lets explain straight road to do that with IntelliJ IDEA:

  1. Clone project (every repository has one link to clone regardless number of branches).
  2. Go to Git => Branches

enter image description here

  1. Choose specific-branch which you need then click on Checkout

enter image description here

That is it :)

Erikerika answered 5/6, 2022 at 3:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.