19

I want to download source code from the master-next branch using git as described in the Xilinx wiki.

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 [email protected] 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 [email protected] 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 the master-next branch and not the master branch? How do I correctly fetch a specific branch using git?

I am using RHEL 6, accessed via PuTTY.

3 Answers 3

16

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.

4
  • "clone command you ran gave you a copy of the whole repository".whole repository means both branches merged ? Apr 29, 2014 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, 2014 at 11:16
  • What I did is this: "git clone -b master-next github.com/Xilinx/u-boot-xlnx.git" is this not correct ? Apr 29, 2014 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, 2014 at 12:01
13

This command should work:

$ git fetch origin [branch]

The above command only fetches metadata from remote repository, it doesn't merge sources.

If you want fetch and merge the sources it should be:

$ git pull origin [branch]

Be careful with the branch where you are executing merge command. That branch will be where the sources are merged.

#UPDATE# grammatical checking/re-writing

2
  • 1
    Your answer is technically correct but I think it might benefit from some grammatical checking/re-writing.
    – user48669
    Apr 29, 2014 at 12:01
  • this works nicely thx
    – nwgat
    Oct 4, 2014 at 1:08
4

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

1
  • 1
    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, 2014 at 11:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .