I downloaded last revision of a big repository, where I need to get a latest revision of one branch so that I can test it.
How do I do that?
When I did git clone --depth 1 url
I got last revision of master and the branch doesn't seem to exist?
petanb@petrbena:~/Documents/mh$ git checkout flaggedrevs
error: pathspec 'flaggedrevs' did not match any file(s) known to git.
git clone --depth=1 <url> creates a shallow clone. These clones truncate the commit history to reduce the clone size. This creates some unexpected behavior issues, limiting which Git commands are possible.
In order to checkout a remote branch you have to first fetch the contents of the branch. In modern versions of Git, you can then checkout the remote branch like a local branch.
The Git clone command will create a new local directory for the repository, copy all the contents of the specified repository, create the remote tracked branches, and checkout an initial branch locally.
git clone --depth 1
implicitly carries a --single-branch
option, which defaults to the primary branch, which is origin/master
by default.
If you want to clone a different branch, tell git which one you want to clone.
git clone --depth 1 --branch <branch> url
You can directly fetch anything you want:
git fetch --depth 1 origin flaggedrevs:flaggedrevs # `origin` can be a URL too
That will create a normal (albeit shallow) branch from what you fetched. To get more conventional results, git fetch --depth 1 origin flaggedrevs:refs/remotes/origin/flaggedrevs
. "copy origin's flaggedrevs to my refs/remotes/origin/flaggedrevs".
Haul up .git/config and look at it, or say git config --get-regexp fetch
. If you don't explicitly tell it what to fetch, that's what it fetches.
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