开发者

Change Git branch on SSH remote before cloning

开发者 https://www.devze.com 2023-03-27 13:59 出处:网络
I am trying to clone a repo from an SSH remote like this: git clone \"ssh://user@project.example.com/var/www/git/www\"

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

git clone "ssh://user@project.example.com/var/www/git/www"

This works OK but using this command I am a开发者_运维知识库ctually cloning the "master" branch of the repo, but instead I want to clone another branch which is called "dev2".

How do I achieve that?


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://user@project.example.com/var/www/git/www"


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://user@project.example.com/var/www/git/www'
git checkout -b dev2 origin/dev2
0

精彩评论

暂无评论...
验证码 换一张
取 消