How to clone the specific branch in git repository?

How to clone the specific branch in git repository?

Here let us discuss couple of ways to clone the specific branch of a particular git project repo.

First option: clones the specific branch using -b option in git clone command,

$ git clone ssh://<usermame>@<hot-name>:<port>/<project-repo> -b <branch>
$ cd <project-repo>

Another option: first clones the master branch which particular git project repo latest branch, and checkouts the required branch in that project repo.

$ git clone ssh://<usermame>@<hot-name>:<port>/<project-repo>
$ cd <project-repo>

Lets check available branches using -a option with git branch command,

$ git branch -a

sample output:

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/branch3
  remotes/origin/branch2
  remotes/origin/branch1

checkout the required branch using git checkout command,

$ git checkout <branch>

Example checkout branch 2 in available branches in remote repo,

$ git checkout branch2

Sample output:

Branch 'branch2' set up to track remote branch 'branch2' from 'origin'.
Switched to a new branch 'branch2'
s


Python installation

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^