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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With