Git clone a branch, not master

67,656

Solution 1

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

Solution 2

if you use git you can do that easily with git clone -b <name_of_branch> <URL_Repository>, if you want to pull do git pull origin <name_of_branch> <URL_Repository> .

Regards

Solution 3

You can use below solution:-

Step1: Clone the repo by using below command following by credentials.

git clone <Repository URL>

Step 2: checkout the branch and pull the latest code from there.

git checkout -b <your origin branch>

Step 3: pull the latest code

git pull origin <your origin branch name where latest code is available>
Share:
67,656

Related videos on Youtube

mister_giga
Author by

mister_giga

Updated on July 09, 2022

Comments

  • mister_giga
    mister_giga almost 2 years

    I use Git Bash for bitbucket. I have created a brunch 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?

  • mister_giga
    mister_giga about 7 years
    I get merge conflicts at the step 3
  • mister_giga
    mister_giga about 7 years
    yes but I have no solution at all, where and how should I mention the repository URL?
  • mister_giga
    mister_giga about 7 years
    what am i supposed to do
  • czar008
    czar008 about 7 years
    I edited my question, the URL goes after the branch name, about you merge conflicts, probably you already have a working copy with changes of other user and need to stash your changes in order to get the latest changes in the branch repository you can do this with git stash in the folder of your working copy
  • Anas Ansari
    Anas Ansari almost 3 years
    @mister_giga I am stuck here too. Were you able to solve it?