Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Clone from a branch other than master

I am trying to pull from a repository in Github. But I don't want to clone the master branch. I want to clone some other branch. When I try git clone <url>, I get the files from the master branch. What should I do?

Also, suppose the code is updated in the repository and I want to get the latest code, should I again use git clone ? Because the size of the project is huge. Also if I make changes to the project locally, and then I again use git clone, will the changes I made still be there? What if I don't want changes to be there?

I am not even sure if git clone is the right command. git pull or git fetch?

I am sorry, I am very new to git.

like image 936
user2510555 Avatar asked Jun 29 '13 18:06

user2510555


People also ask

How do I clone a branch other than main?

git-remote add To clone a branch without fetching other branches, you can use the git-remote add command with git-fetch. The following example first creates and initializes an empty git repository. Then it adds a remote named origin for the specified repository and fetches the specified branch from the origin.

Can you git clone 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 down a specific branch?

In order to clone a specific branch, you have to execute “git branch” with the “-b” and specify the branch you want to clone. $ git clone -b dev https://github.com/username/project.git Cloning into 'project'... remote: Enumerating objects: 813, done.


1 Answers

Try this:

git init git fetch url-to-repo branchname:refs/remotes/origin/branchname 

EDIT

A better solution:

git clone -b mybranch --single-branch git://sub.domain.com/repo.git 
like image 189
Aguardientico Avatar answered Sep 18 '22 19:09

Aguardientico