Change Git branch on SSH remote before cloning

I am trying to clone a repo from an SSH remote like this:

git clone "ssh://"

This works OK but using this command I am actually cloning the “master” branch of the repo, but instead I want to clone another branch which is called “dev2”.

  • Deploy once a specific branch with capistrano?
  • Dynamically Fill Jenkins Choice Parameter With Git Branches In a Specified Repo
  • How do I manage conflicts with git submodules?
  • Git: How to push from “no branch” to a new remote branch?
  • Identifying a tag belongs to which branch in git
  • Why do I need the “master” in git merge origin/master?
  • How do I achieve that?

  • How to connect github with visual studio code?
  • Git - multiple repositories?
  • Merging Git Flow Feature Branch after Hotfixes?
  • Auorefresh git log after commit when running in the Terminal
  • Find all current lines modified by an author
  • Risks of adding a remote git repository to current git svn repository
  • 2 Solutions collect form web for “Change Git branch on SSH remote before cloning”

    after git clone.

    you can just

    git branch --track dev2 origin/dev2
    git checkout dev2

    to change your branch to dev2 easily.

    or a short cut

    git clone -b dev2 "ssh://"

    with git you generally clone complete repositories (all branches). if you want to clone only a single branch and never get any other branches use the following commands:

    git init project
    cd project
    git remote add -f -t dev2 origin 'ssh://'
    git checkout -b dev2 origin/dev2
    Git Baby is a git and github fan, let's start git clone.