- In the last video I showed you how to clone a basic
GitHub repository.
And one thing we didn't talk about is branches.
That's because when you clone a repo, you can only see
the master branch of the project.
The other projects are there but they're hidden.
So let's take a look at how you can get specific branches
or download a project with all of the branches.
So this time I'm going to work with a different project,
I'm going to go to my home page at GitHub and then
go to the Repositories tab
and then find the one called responsivebootstrap.
It's right here.
Then I'm going to go to the clone URL section here
and copy the URL to the clipboard
and then I'm going to go over to my Terminal,
make sure that I am on the desktop.
So I'll do cd ~/Desktop
and then I'm going to issue the git clone command.
Let's go ahead and make this window bigger.
And just paste that URL
and you'll notice that it'll clone the repository
into a folder called responsivebootstrap.
So that folder is on my desktop.
You'll notice that there's another folder here.
That's actually something that I had there before.
I'll talk about that in a minute.
Now if we take a look at the instructions for this
repository, it's also going to tell you that you need
to have node.js, git, and gulp installed.
You can click on those links to get instructions on how
to install those.
And then we need to switch over to the directory
cd responsivebootstrap.
And as usual we're going to run the npm install command.
That's going to install all the dependencies.
You may have to run it using the psuedo command
depending on your permissions.
And once that is all done,
I'm going to go ahead and issue a clear command,
we can run the gulp command and that's going to run
our automation for this project
and then open the project in our browser automatically.
So that's pretty cool and you'll notice that this project
has a git ignore file.
You may notice that none of the images are here.
That's because inside this repository we have a git ignore
file that tells git not to save any of the images,
or not to upload any of the images, to GitHub.
And that's why I put this images folder right here.
It's not really necessary for what we're doing but
I know it would probably bother some people
that we can't see the images here.
And let's go ahead and add those in.
So I'll open up this responsivebootstrap
and this should go in builds, development,
and somewhere in here.
So I'll drag the images folder right there
and if we refresh you should see all
of the images appear on the project.
So not something we necessarily need
but it's sort of cool.
Actually I'm going to take this images folder
and make a copy of it on the desktop
because I may need them a little bit later.
So on a Mac I'd click + drag and hold down the option key.
You can also copy and paste.
And then I'm going to close that out
and just show you the gitignore file
has this images folder not being uploaded into GitHub.
We can take a look at some of these other invisible files.
We have a jshint that's pretty cool.
This project has a lot of a automation built in that's
going to check your JavaScript for you.
It's going to check your HTML to make sure that it is valid.
And it does a lot of other stuff in
this gulp file right here.
The important thing that I wanted to show you is that
if we take a look at the branches available in this project.
So I'm going to open up a new tab, it's cmd + t on a Mac.
On a PC you may have to open up a new git bash window.
You can also just ctrl + c in here and stop the automation.
But it's kind of nice to keep it running on a separate tab
and then use another tab to issue git commands.
So if we do a git status, you can see that everything
is up-to-date.
If we do a git branch, you're going to notice that
it really only pulled one of the branches.
And so what if you want another branch?
Well, now git did pull all the information for
all the branches in this project.
It's just not downloading any of the additional branches.
So if you do a git branch -a command
you're going to see all of the branches
that you would normally see in GitHub.
Now notice that they're all red right now.
It means that it didn't pull any of those files.
The only one that it grabbed was this one called master
and notice that there is sort of a little pointer.
That means that it actually created a local copy of that
branch and it's the thing that you're accessing right now.
So if we wanted to pull a different branch
what you would do is execute a git checkout command
and the do a -b for branch,
and then pull the branch that you want to check out.
So let's say I wanted to pull out the branch
that is 02_01
so this branch right here.
We don't need to type all this other stuff in,
just the name of the branch.
And then what we want to do is type in location of the
origin of this branch so
origin/02_01.
So actually let me clarify something because I don't know
if I said this correctly.
So this is going to be a branch that I'm going
to be creating by issuing this command.
This is the location of the branch on GitHub
so we do have to put in this origin part.
What we're saying here is go ahead and grab the branch
called 02_01 from GitHub and then
make a local branch called 02_01.
They don't really have to be the same name but it's
probably a good idea to keep them the same.
And then check it out and add it to this project.
So if I execute this command you'll see that it's going to
switch to that branch so you should see the project.
Because it has some automation built-in
the project actually switched to an early version
of what it looked like in chapter two, movie one.
And if we do a git branch command
you can see that now we have two branches and
the star is on the branch that we just pulled.
So this command right here did a few things.
It checked out a branch from our remote server from GitHub,
right this branch called 02_01,
it made a new branch in our local project called 02_01,
and it downloaded everything from GitHub
and then automatically switched to that branch.
So it did quite a few things.
If we want to get back to the other branch it's just like
with any other project.
We could do git checkout master
and continue to work with our project.
So this project has a lot of automation so you see that
this window automatically updated.
So what's actually happening is we have a gulp command
that whenever it notices a change in the file structure,
it's going to rerun all those files and automatically
reload the browers.
That's why it's doing that automatically when we go
to a different branch.
Now for a very large project though, it's sort of annoying
to have to pull each of the branches individually like this
because if we wanted to get every single one
of these branches we would have to execute this
git checkout command quite a bit.
So there's actually a way of pulling all of the branches
at once and it's a little bit complicated but I use this
all the time especially when I want to go back
into a project and just pull everything that GitHub has
at once.
So what I'm going to do is go ahead and
delete this folder right here.
This is my project.
I want to make sure that I close out my automation.
It's probably going to complain at some point
when it notices that the folder is not there any more.
So I'm going to close out this window and Terminate.
And I want to run a series of commands that is going to
download everything, all the branches that you see over here
in GitHub.
So commands work like this.
So what we need to do first is create a directory for
this project.
So we don't have a folder.
We actually have to make a new one.
So I know I want to be on the desktop.
Right, let's go ahead and clear this out.
And in the desktop I'm going to issue a mkdir,
that means make a directory.
You can also just right click and select New Folder
and do that on your desktop if you want to.
So we'll do a
mkdir responsivebootstrap.
You can call it whatever you want but this is what we
called it originally.
So do that and then I'm going to switch
to that directory.
And you'll notice that the folder appears on the desktop
I'm going to switch to responsivebootstrap.
And then I'm going to clone the repository
but in a slightly different way.
So what I want to do here is make a mirror
of the repository.
So I'll do a git clone --mirror
and then I'm going to paste the git URL.
So I'll go back into GitHub
and find the clone URL
and just copy it to the clipboard.
I'm going to paste that, and then I'm going to add
a space here and do .git.
This is very important.
You want to do a space after this .git
and then .git again.
So it's essentially we're copying the invisible git folder
that keeps track of everything in our project
from GitHub.
So let's go ahead and execute that command.
So notice that it's saying that it's cloning this into
a bare git repository.
Let's go ahead and open this up into my text editor.
You can see that inside that folder, we're not really seeing
anything in there.
There's nothing in there quite yet.
Let's do an ls command and you'll notice that there is
actually an invisible git folder.
So blank just doesn't show you the invisible git folders
by default but you can see that the terminal is showing us
that it actually did clone something
and what it grabbed is that entire git folder
where all the files are kept track of by git.
And the next thing we need to do is make sure that
we're inside that folder so let's make sure that we are in
responsivebootstrap, right.
And then we're going to do a
git config --bool
so this is a boolean value that we're modifying
to take this from being a bare repository
which is just a repository with nothing in it
except for that invisible git folder.
And we'll say core.bare so we're switching it
from a bare repository into a regular repository.
So core.bare false.
We'll do that and we're not quite done yet.
We need to do one more command.
This will be a git reset --hard command.
This is a hard reset.
What it's going to do is essentially grab everything
that is inside this folder and create all of the branches
and make it look like a normal repository.
So now if we go into our project you can see that we have
everything that we used to have before, the gitignore file,
everything is in there if we open this up on the desktop
you'll see that all the files reappear.
We still have the basic git folder.
Right, we still have this folder.
But now, let's go ahead and clear this out.
If I do git branch, you'll see that all of the branches
were pulled down from the GitHub repository
and work with my entire structure for this project
including any of the previous branches or any of the
previous logs that I have done.
So just as before I'm going to go ahead
and delete this folder.
This is just sort of an example.
You could do that to download any GitHub repository
and grab all of the different branches.
That's really useful.
If you want to see this project, you can install things,
and copy this images folder back in there.
But we don't really need to keep any of these files.
I just wanted to show you how to grab a folder from GitHub
with all the branches.
Now the ability to clone all the branches on a project
is pretty cool but it's not something you're going to want
to do for every project.