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”.

  • git branches diverged after rebase
  • Handling temporary changes (not to be committed) in Git
  • How to push a new branch non-existing on the remote server without --set-upstream?
  • Keeping Git branches up to date while waiting for them to be merged into upstream
  • move some commits to a new branch in Hg
  • Show just the current branch in Git
  • How do I achieve that?

  • How to make git consider .strings files as text file instead of binary file
  • MYSQL development workflow with git versioned scripts
  • No refs in common and none specified; doing nothing
  • Merging two branches without actually merging
  • Workflow with git-flow feature branches and Gerrit
  • How to keep file sync'd in OpenShift?
  • 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.