Git: Checkout a Remote Branch

To checkout a remote branch using git, execute the following commands:

/tmp git clone git@github.com:wolfoo2931/example-repo.git
/tmp cd example-repo
/tmp/example-repo git:(master) git fetch origin
/tmp/example-repo git:(master) git checkout -b feature-branch origin/feature-branch
/tmp/example-repo git:(feature-branch)

If you want to list all available remote branches execute the branch subcommand with the -r option (r stand for remote).

/tmp/example-repo git:(master) git branch -r
origin/HEAD -> origin/master
origin/feature-branch
origin/master

If you want to clone specific branch without checking out the master branch you can simply run:

/tmp git clone git@github.com:wolfoo2931/example-repo.git -b feature-branch --single-branch
/tmp cd example-repo
/tmp/example-repo git:(feature-branch)

To checkout a tag run:

/tmp git clone git@github.com:wolfoo2931/example-repo.git
/tmp cd example-repo
/tmp/example-repo git:(master) git fetch origin --tags
/tmp/example-repo git:(master) git checkout tags/v1.0 -b v1.0
/tmp/example-repo git:(v1.0)