- [Cameron] Hey, I'm Cameron McKenzie.
I'm the Editor-in-Chief over at TheServerSide.com,
and you can follow me on Twitter @cameronmcnz.
And I wanna talk to you about
doing a git clone with a depth of one.
So I have my git lab repository right here.
And as you can see, the master branch,
if I take a look at it,
it's got quite a deep commit history.
Now let's say I'm usin' Jenkins,
or doin' some sort of continuous integration,
and I just wanna pull the latest commit for master.
I don't want this whole history.
And for that matter,
I don't want the whole history of the release branch
and the develop branch.
I just wanna maybe pull a master, do a compilation
on it, run through all my static code analysis.
And if it works?
Hey, why not just push it to pre prod
or something like that.
I don't need all of these commits.
I just need the latest one.
And so, the way you can clone a repository
and get just the latest commit from it,
is to use a commit depth.
So, here's how you do it.
Actually I need to first get the URL of the repository.
You can get that from the clone.
If you're using git hub,
there'll be a git code link.
And basically you need the HTTP URL for the repository.
And ya just issue this simple command.
It's git clone.
But it's git clone and then it is dash dash depth.
And we just specify one.
And then ya do a little paste here.
(keyboard clicking)
And all of a sudden we have now cloned the repository
to a depth of one.
Now let's just prove that out.
I'm gonna go into this git lab made easy folder.
That's where I cloned to.
Then do a little LS command.
So it looks like all of these files are here.
I'm on the master branch.
But now let's take a look at the git commit history.
So I'll do a git log one line, one commit.
That's it, there's no other commits there.
But look at the commit history from the master branch.
Like it goes on forever.
Well it goes on for a scroll anyways.
And just to prove to you the difference, I can clone
the repository like normal.
But actually before I do that,
just let me show you one other thing.
Ya notice that I've actually got git flow going on here.
I've got the developer lease and hot fix branch.
If I come in here, and I do a git branch dash all,
to see all the branches.
I don't have develop hot fix or release.
I can't even check 'em out.
I can't do -
Git checkout.
(keyboard clicking)
If I try and do that, I get an error.
So just to quickly do a comparison,
why don't we just compare that to not specifying
the depth at all.
Just to demonstrate, ya know, how it works.
And if you wanna do a clone to a separate folder,
you just specify the folder name at the end
of the git clone.
So I've removed the depth.
I've specified a folder name, fully completely.
That's a tip of the hat to the Tragically Hip.
Great album.
And now I've cloned that whole repository
into fully completely.
So I'll move in there.
(keyboard clicking)
And if I come in here and I do git log one line.
You're not gonna see one commit.
That's the only commit we saw in the other cloned repository
with a depth of one.
It's not goin' on here.
And if I do a git branch all,
you can see I've got the develop hot fix
and release branches, along with master.
And if I just do a git checkout,
it's not a problem.
You can see that I'm on the develop branch.
So there ya go.
That's what's involved in doing
a git clone branch depth of one.
And that's all there is to it.
Depth of one, couldn't be easier.
So anyways if you like this tutorial, head over
to the TheServerSide.com, where I am the Editor-in-Chief.
Lot's of git, git lob, dev ops, software development,
and just any information that has to do
with Server Side software up there.
And if you're interested in my antics, follow me
on Twitter @cameronmcnz.