Search code examples
gitbranchbitbucketgit-bashgit-clone

Git clone a branch, not master


I use Git Bash for bitbucket. I have created a branch and I pushed some commits, other people pushed commits in master. Now I am on a different machine. I want to clone or download the solution of the latest commit of my branch and not the master? How can I do that?


Solution

  • I think you are looking for the --branch option to git clone, which allows you to specify which branch is initially checked out in the cloned repository.

    git clone --branch mybranch $URL/foo
    

    is roughly equivalent to

    git clone $URL/foo
    cd foo
    git checkout mybranch
    cd ..