Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning specific branch

Tags:

git

github

I am new to git version control and I dont know how to clone / pull a specific branch of a repo . Trying to get the branch master of the project, but it defaults to branch test_1

I have tried using the command git clone but it grabbed default test_1. I have also tried reading other questions but the commands are confusing me and I dont want to break anything.

How do i clone the master branch of this project so i can make changes and push to it?

like image 904
Jeff P Avatar asked Dec 20 '16 01:12

Jeff P


People also ask

How do I clone only a specific branch?

There are two ways to clone a specific branch. You can either: Clone the repository, fetch all branches, and checkout to a specific branch immediately. Clone the repository and fetch only a single branch.

How do I clone a specific branch in Azure DevOps?

From your web browser, open the team project for your Azure DevOps organization, and then choose Repos > Files to open the Files view. In the Files view, choose Clone to launch the Clone Repository popup. Copy the clone URL from the Clone Repository popup.

How do I clone a specific branch in git GUI?

Steps as below: Git GUI -> branch Tab -> checkout -> Tracking branch -> select origin/dev -> checkout -> branch Tab -> create -> name for dev and select this detached checkout -> create. Now you have a local dev branch the same as remote. You can check the history by repository Tab -> visualize dev's history.


2 Answers

You can use the following flags --single-branch && --depth to download the specific branch and to limit the amount of history which will be downloaded.

You will clone the repo from a certain point in time and only for the given branch

git clone -b <branch> --single-branch <url> --depth <number of commits> 

--[no-]single-branch


Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary branch remote’s HEAD points at.

Further fetches into the resulting repository will only update the remote-tracking branch for the branch this option was used for the initial cloning. If the HEAD at the remote did not point at any branch when --single-branch clone was made, no remote-tracking branch is created.


--depth

Create a shallow clone with a history truncated to the specified number of commits

like image 115
CodeWizard Avatar answered Sep 30 '22 19:09

CodeWizard


you can use this command for particular branch clone :

git clone <url of repo> -b <branch name to be cloned>  Eg: git clone https://www.github.com/Repo/FirstRepo -b master 
like image 27
aks7 Avatar answered Sep 30 '22 19:09

aks7