Intellij git: clone specific branch

21,947

Solution 1

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.

Solution 2

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

Solution 3

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

Share:
21,947
Daniel Fensterheim
Author by

Daniel Fensterheim

Updated on July 05, 2022

Comments

  • Daniel Fensterheim
    Daniel Fensterheim almost 2 years

    I am new to Intellij. 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?

  • granadaCoder
    granadaCoder over 5 years
    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.