Cloning a specific branch

I'm new to git version control and I don't know how to clone / pull a specific repo branch. Trying to get the master branch of the project, but by default it has the test_1 branch

I tried using the git clone command, but it grabbed test_1 by default. I also tried to read other questions, but the teams confuse me, and I do not want to break anything.

How do I clone the main branch of this project so that I can make changes and click on it?

+6
source share
4 answers

You can use the following flags --single-branch && --depth to load a particular branch and limit the amount of history that will be loaded.

You clone a repo from a certain point in time and only for this branch

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

- [no-] one branch


Only the history leading to the tip of one branch is --branch , either indicated by the --branch option, or by --branch primary HEAD branch.

Further submissions to the resulting repository will only update the remote-tracking branch for the branch, this option was used for the initial cloning. If the HEAD on the remote control did not indicate a single branch when the --single-branch clone was created, no remote tracking branch is created.


- depth

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

+24
source

You can use this command for a specific industry clone:

 git clone <url of repo> -b <branch name to be cloned> Eg: git clone https://www.github.com/Repo/FirstRepo -b master 
+10
source

I donโ€™t think you fully understand how git gives you the whole history of all branches by default.

git clone --branch master <URL> will provide you with what you want.

But in fact, in any of the other test_1 where you ended up with test_1 , you could just do a git checkout master and it would switch you to the main branch.

(What @CodeWizard says is true, I just find it more advanced than what you really need.)

+5
source

a git repository has several branches. Each branch follows a development line, and it has its origin in another branch at some point in time (except for the first branch, usually called master ), which starts as the default branch until someone changes, which almost never happens)

If you are new to git, remember these 2 basics. Now you just need to clone the repository, and it will be in some branch. if the branch is the one you are looking for, amazing. If not, you just need to switch to another branch - this is called checkout. Just type git checkout <branch-name>

In some cases, you want to receive updates for a particular branch. Just do git pull origin <branch-name> and it will โ€œloadโ€ new commits (changes). If you have not made any changes, this should be easy. If you also make changes to these branches, conflicts can occur. let me know if you need more information on this case.

+5
source

Source: https://habr.com/ru/post/1013317/


All Articles