Question

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.

Was it helpful?

Solution

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

OTHER TIPS

git clone <url>

clones and creates remote-tracking branches for each branch. If you want to see available branches (after cloning), you type

git branch -l

To switch to a particular branch after cloning you do:

git checkout <branchname>

where branchname is the name of the branch :)

If you want to clone and checkout a specific branch you do

git clone -b <branchname> <url>

The other commands you mention are for "updating" your current working copy. git pull gets all changes from the remote repository and merges them while git fetchonly gets them without merging.

use git clone --branch <name> possibly adding --single-branch

as usual you have git clone --help to read details on commands

If you already cloned the repo and want to contribute to the branch other than master, do this:

$ git checkout --track origin/<branch-name>

Of course, be sure to specify the right name of the remote (origin in the example above)

This command will create a new local branch that will track a particular remote branch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top