Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

OS: RHEL 6

I want to download source code from the following link using git :

master-next

described here.

I tried this:

#git clone git://github.com/Xilinx/u-boot-xlnx/tree/master-next.git

Initialized empty Git repository in /home/Hannan/master-next/.git/
fatal: remote error:
Xilinx/u-boot-xlnx/tree/master-next is not a valid repository name
Email support@github.com for help

Even this failed:

# git clone git://github.com/Xilinx/tree/master-next/u-boot-xlnx.git
Initialized empty Git repository in /home/Hannan/u-boot-xlnx/.git/
fatal: remote error:
Xilinx/tree/master-next/u-boot-xlnx is not a valid repository name
Email support@github.com for help

The command that works is:

 git clone git://github.com/Xilinx/u-boot-xlnx.git

But how do I know that this will indeed fetch master-next branch and not the master branch?

Another limitation is I am accessing the machine using putty.

How do I correctly fetch specific branch using git?

share|improve this question

3 Answers 3

Like the error message tells you, git clone expects a git repository. You can't "add" the name of a branch in the path like that. See branches in git.

You can clone a single branch (and it's history) : git clone <url> --branch <branch> --single-branch

See git help clone.

But the clone command you ran gave you a copy of the whole repository, you can see the existing branches with git branch and more details about them with git show-branch.

Switch to the branch you want with git checkout branch-name.

The first chapters of the Pro Git book (available online) give more details on the basic commands.

share|improve this answer
    
"clone command you ran gave you a copy of the whole repository".whole repository means both branches merged ? –  user2799508 Apr 29 at 11:10
    
No they are not merged. A branch in git is not a copy of the whole directory, as explained here. –  Leiaz Apr 29 at 11:16
    
What I did is this: "git clone -b master-next github.com/Xilinx/u-boot-xlnx.git"; is this not correct ? –  user2799508 Apr 29 at 11:47
    
You didn't need clone anymore. The command you showed in your question gave you the repository with all the branches. But this is correct too. It's equivalent to doing git checkout master-next after cloning. –  Leiaz Apr 29 at 12:01

git repositories contain all branches (but compressed and only differences hence rarely a size issue).

Therefore, you can clone the entire project as you have done successfully. This is a standard way to get a repository, even if you are only interest in one branch.

The .git structure will then include all the branches done on that repository.

To use a specific branch do git checkout [branch_name] If the branch exists the files will be made available locally (as just that, the current files in the project directories).

git status will then show which branch is the current branch, for example:

According to Leiaz one can clone a specific branch. In practice I've never done this or seen others use it. On further research, I see it is relatively new, added in git 1.7.10 (April 2012): 'git clone learned --single-branch' option to limit cloning to a single branch (surprise!); tags that do not point into the history of the branch are not fetched. For example:

git clone -b master-next --single-branch git://github.com/Xilinx/

enter image description here Here, for my "linker" application I am checking out branch v3.0.10

share|improve this answer
    
I've never done it either, I remembered seeing the option. I guess it's rarely used as extra branches are "cheap" in size. –  Leiaz Apr 29 at 11:43

This command should work:

$ git fetch origin [branch]

The above command only fetch metada from remote repository, not does merge sources.

May be that you need a 'git pull' command that fetch + merge sources?

The command would be:

$ git pull origin [branch]

Be care with place from you are executing merge command. Will be there where sources merge.

share|improve this answer
    
Your answer is technically correct but I think it might benefit from some grammatical checking/re-writing. –  Sami Laine Apr 29 at 12:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.