Check out a free preview of the full Complete Intro to Web Development, v2 course:
The "Git and Bash" Lesson is part of the full, Complete Intro to Web Development, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Brian introduces git, which is a distributed source control management tool. To use git, Brian demonstrates how to work on the command line with bash.

Get Free Access Now

Transcript from the "Git and Bash" Lesson

[00:00:03]
>> Brian Holt: Welcome back, friends. You survived this far, we have a few fallen amongst us. [LAUGH] That trying to be for sticking it out. So we're gonna take a brief detour from Java Script. What we're about to talk about right now has nothing to do with Java Script, or maybe better I say that it has to do with all programming.

[00:00:29] So when we back into our command line we're gonna be using something called Git. And we're going to be interacting with git being a command line, and the way that we're doing that is with Bash which is the shell so we kinda get a little bit of the preview before when we were messing up with node and parcel.

[00:00:46] But now, we're gonna be messing around with Git. Unless you're on Windows, Git is already on your computer. I guarantee you that Git is on Mac and I guarantee you that Git is already in Linux. I don't think it's already on Windows. So I gave you a link here, right, for Git for Windows.

[00:01:05] And you should just come down here and you download this and this is Bash-like, it's not totally Bash, but it's very, very similar to Bash. So go down on that if you're on Windows.
>> Brian Holt: The first thing I want to tell you is that you never have to use the command line as a programmer.

[00:01:31] That being said, it's kind of a super power, it's gonna make you a better developer if you spend the time to learn the shell. But I have worked with developers that have been developers for a decade, and have not learned the command line. But, that being said, do.

[00:01:46] Please do. Git in particular, GitHub has a really nice GitHub GUI. Yeah, desktop.github.com. They have a really nice client that you can interact with GitHub and Git and all these kind of things. Just using this program, right? GUI stands for Graphical User Interface, you will see that it refer to it was GUI or GUI, that's just the fancy way of saying this application, okay?

[00:02:17] See, you can use Git this way, there's another one called Sourcetree as well, that's really quite popular.
>> Brian Holt: And that's from our friends at Atlassian, and they make that one as well. So you are welcome to use those. I would invite you to actually go ahead and learn how to use Git using the command line.

[00:02:40] I think it's a good idea. That's how I do it personally. And many developers are now do it that way as well. So what we're gonna do is we're gonna come to here or something I have not taught you yet. This is a program and it's still running, right?

[00:02:55] But I want it to stop, right? Cuz I'm not using my development server anymore. The way you do that is Ctrl+C and that's the same across Windows, Linux and Mac as well. So if I hit Ctrl+C, it stops. And that's just kinda the universal way with Bash and general, please stop doing whatever you're doing, right?

[00:03:18] So for example if I say, ping www.google.com. This is going to keep hitting the Google service to say, are you there? And Google is gonna say, yes, I'm there. Right, so that's what this does. And it's going to keep doing until I tell it to stop. So the way it tells to stop is Ctrl+C.

[00:03:35]
>> Brian Holt: So.
>> Brian Holt: Make sense? Ctrl+C is something you definitely need to know.
>> Brian Holt: So we're gonna work a little bit with Bash. So you've seen cd and ls, so cd is change directory. So, if I'm in popdemo for example right now. Let's say I wanna get backup to desktop, so what I'm gonna do is say cd, change directory, space That means go up.

[00:04:08] Okay, so you can see here, now it was on popdemo, now I'm back on desktop. I wanna see what's on my desktop, so I hit ls. You can see that I have animation, I have all these folders on here, right, I wanna go back into popdemo. Hit ls and you can see everything that's in there right?

[00:04:29] So you can kind of get them like navigating around, this is exactly analogous to if I was here in my Finder and I want to among my desktop and I go to popdemo and click into there, right. Same thing, this is just a graphical user interface for what I was doing.

[00:04:49] Makes sense? I'm gonna type clear which clears everything off. If you hit pwd, you'll see where you are. It's basically like asking, where am I, to Bash. I think it stands for present working directory.
>> Brian Holt: Print Work Directory, Print Working Directory rather.
>> Brian Holt: So for the most part, let's see if I go here, if I pwd Users and the name of my user on my computer is btholt.

[00:05:29]
>> Brian Holt: So if I go back here to the Desktop, and do take note that this is case sensitive. It is on Linux it's not on Mac, actually. I think that's the case. So if I hit cd desktop.
>> Brian Holt: It does work. Which is unfortunate cuz it causes problems.

[00:05:47] Anyways every user on Linux and Mac, cuz Linux and Mac share a common ancestor which is called the Unix. So they work relatively the same way when it comes to the command line. They work the same way, that's why if you're on Linux you're able to follow along.

[00:06:02] Windows works a different way, it has a different thing that is based on Windows, follows. However, Windows does now have something called the Linux sub system, that you can actually use directly on Windows, only on Windows 10. I put directions to do that on the tools section of this workshop, if you want to try that.

[00:06:23]
>> Brian Holt: Okay, so I'm on desktop, I go into popdemo. I was talking about home directories, every user has a home directory. So you can see here /Users/btholt, that is my personal home directory. That's most of the time you're gonna be working out of your own home directory, unless you're doing some crazy stuff.

[00:06:42] Which don't do too much crazy stuff. But that's what this tilde means, this little squiggly, which is the key right next to one if you hit shift, that's a tilde right there. Tilde is just a shortcut to mean your home directory. So if I hit cd ~ it means go to my home directory immediately.

[00:07:01] So I'm gonna go from desktop/popdemo directly to my home directory which is what that tilde is, right? Okay, so I'm gonna go now to desktop/popdemo. Let's talk about what else, I'll talk about ls a little bit. So ls shows you what's in your directory, it stands for list I can also pass it a flag to say, hey show me hidden files.

[00:07:26] So if I've put -a, it's gonna show me all the hidden files in there as well. Which you can see that there's .cache, that's new as well. Like that's hidden up here whereas and dot and you can ignore those top two but. Anything that's preceded by a dot is hidden and the reason that I hide .cache is like it's not actually very useful.

[00:07:48] It's a tool for parsel, parselUsers.cash. So that it can rebuild things more quickly. So that's what -a means. If I put- or ls -lah, I get this nice big list, right? It's the same things, right? But the a represents show it all, everything, so that's why you still see cache.

[00:08:13] -l means show it in this list style, right? And h means show these, so this is like 352 bytes. 1.7 kilobytes. 1.3 kilobytes. Where's node modules? So if I, yeah, anyway. That's what that does, is it shows it in a more useful way. If I did ls-la, you would notice that these sizes are decidedly harder to read, right?

[00:08:40] This said 1.7 kilobytes. Now, it's 1760 bytes. So anyway, this makes it a little bit more usable if you put -h. Those are called flags. You would just have to know what they are [LAUGH] unfortunately, and it's different for every program. So there are literally hundreds of them, and I only know maybe a small set of them, so.

[00:09:06] In fact let's take a look at how you can find more out. If I put man.ls, it's gonna pop up this thing that I can actually browse through and see the documentation for LS. You can see that it's quite long.
>> Brian Holt: Really, really, really, really long [LAUGH] But, that's how you look at documentation.

[00:09:35] To be honest, I don't really look at the main pages very much, mans stands for manual as you might have guessed. When you wanna get out of man pages you just hit Q, which stands for quit, okay. That'll take you out of a man page. What's actually a little bit more useful is there's this thing called explainshell, that if I click on.

[00:10:01] If I put in ln-lah then it'll actually explain to me what each one of those things does. So h stands for human readable, I didn't know that, I just knew that I had put lah. But I can put anything in there. If I put node-v, it figures out that node, and doesn't know what -v is but it means version.

[00:10:22] maybe like git-v. The stupid contract. It doesn't know what a dash is either. Anyway, it knows about a bunch of these things like if I put pwd in there it knows print name of current working directory. Or SFTP, Secure File Transfer Program. So, explainshell is very, very useful for trying to figure out what shit does.

[00:10:52]
>> Speaker 2: There's no life page?
>> Brian Holt: There's no what?
>> Speaker 2: Life page.
>> Brian Holt: Life page?
>> Speaker 2: You searched for it.
>> Brian Holt: [LAUGH] What is life? No man page for life, unfortunately. It will all explain everything to you. Where was I?
>> Brian Holt: Go back through these a little bit. Okay.

[00:11:28] Back in Git. So, just to kind of give you an example, I'm gonna go back up to my desktop. I'm going to say, make a new directory, which is mkdir, and it's gonna be called Some-cool-thing, okay. So now if I look at here, I have a thing called some-cool-thing.

[00:11:53] It's a new folder. I can do cd. Some cool thing is really burdensome for me to type, and you all know by now that I'm quite lazy. So if I do so, sl and if I hit Tab, because nothing else starts with sl, it's like cool, I'm just gonna complete that for you.

[00:12:13]
>> Brian Holt: Or if I come back in here and you can see that there are nothing sort of the same thing, that's usually doesn't happen. If I go up one more, right? If I do d, there are three things that start with d, right? Documents, Downloads and Desktop. There are three things that start with document or with d, Documents, Downloads and Desktop.

[00:12:36] So if I do cd capital D and I hit Tab. It's gonna say, no, I'm not gonna do that. If you hit Tab twice, it'll actually show you, here are your three options. I need you to keep typing, okay? So, if I do, Do, it still says, no.

[00:12:53] You still got Documents and Downloads. If I could see this, then it's like, okay, I will auto-complete that for you, okay? So that's how tab completion works. I'm gonna go back into Desktop. And I'm gonna go into some-cool-thing. I'm gonna use touch. So, let's clear also the top.

[00:13:15] I say touch index.html. Then it's going to create a new file. So If I click in here, now I have new empty file called index.html. If I wanted to just put like an h1, Hi this is cool.
>> Brian Holt: So I can actually like, and I'm gonna put that inside of quotes.

[00:13:40]
>> Brian Holt: I can then say with the angle bracket, put that inside of index.html.
>> Brian Holt: Or no, you have have to echo, rather. So echo that into index.html. So now if I look at index.html, I can look at what's inside of it by saying more, more index.html. I can see that it's in there.

[00:14:07] You can also say cat, that one is for you, cat index.html it will also print that out. What is cat even stand for, I don't even know, concatenate and print. What stands for cat, I'm not sure. So, that's an interesting thing as well, like a really interesting thing that you can do as well.

[00:14:28] Let's say I wanted to copy everything that's inside of index.html into my pasteboard. So like I copy it as in like copy/paste, right. What I can do is I can say cat index.html, then you can put a pipe which is like pipe this into something else, so take the output of this one and put it into the next thing.

[00:14:49] And I can say, pbcopy, which is pasteboard copy. So now if I paste, it's actually in there, it pastes it out, which is pretty cool. Or it copies it, anyway.
>> Brian Holt: Little bit more advanced use cases of Bash, but hopefully I'm showing you that there's a lot of stuff you can do with Bash.

[00:15:10] I'm just really scratching the surface here. If you come into VSCode in particular, if I hit Shift+Cmd+P, it brings up what's called the Command Palette. And if I say, install is you can do this top one, it says shell command install code command. So this will install a Bash program basically, that you can call a code from the command line, which is very, very useful.

[00:15:39] So if I come back here, let's say I wanna edit that index.html file, I can just say code index.html. And it's gonna open this and I can now edit it over here, very convenient.
>> Brian Holt: The last thing I'm gonna show you is I'm going to show you how to exit them.

[00:15:59] [LAUGH] Cuz at some point somewhere you're gonna be thrown into vim and you're gonna be like, how the hell do I get out of this hellscape? [LAUGH] Literally the most Googled thing on stock overflows, how the hell do I get out of them, it's like, at any given time like 4% of their traffic or something ridiculous like that.

[00:16:20] So I'm gonna say vi index.html and I'm suddenly put into this program that I have no idea how to get out of. Typically, I would say Ctrl+C but it says your Ctrl+C powers have no power here. Right? You're stuck here forever. So I'm in this editor and like I don't know how to get out, right?

[00:16:43] Sometimes Git will throw you in tears. So this just kinda happens to people. I don't know what to do they just kinda close the window [LAUGH] That's what I did for a long time. So this is a text editor, so you can, if I hit I, I will go into insert mode and I can actually edit things in here.

[00:17:00] Hi this is from vim, please help me, I'm so scared. I've been here too long.
>> Brian Holt: Okay, if I hit Escape, then I get out of insertion mode, right? And I get back into what's called command mode. And what I'm gonna type now is, if I hit :q, which is the way that I would normally quit.

[00:17:27] It's gonna say, not so fast [LAUGH]. You have unsaved changes, I'm not gonna let you quit with unsaved changes. Now I could do one of two things. I can hit :w, which will save it, it will write it. Or I can hit colon Q exclamation point, which is like, I don't care.

[00:17:45] Get me out of here. So what I'm gonna do is, I'm gonna do :wq, which is going to both write and quit. And then I am out. So just remember :q gets you out of vim.
>> Brian Holt: Okay? I think Jem's course goes a little bit more into more vim magic.

[00:18:10] I don't, honestly I don't know much more than that. I know just like a bare minimum now. The reason why it's useful to know like this much vim, is like if you ever remote into someone else's server and you need to edit a file, you can't use code to edit files on a remote server, you need to use something that's on a server, so vim is on every server.

[00:18:27] So you can just open vim up, make your bare minimum changes, and then get out.
>> Brian Holt: Yeah, and if you want more Bash skills, definitely check out Jem Young's course, he has Full Stack and Full Stack 2, good stuff.