This workshop will be retired on May 31, 2020.
Git-ing the Lay of the Land8:33 with Gabe Nadel
Let's explore what Version Controls Systems are and why they are so important to modern development. In addition, we'll talk about what makes Git so useful as well as some of the common tasks you''ll be performing.
[SOUND] Hello again, my name is Gabe and 0:00 I'm an iOS teacher here at Tree House. 0:04 Today we're gonna introduce you to Git, 0:08 GitHub, and how they relate to your work as an iOS developer. 0:10 We'll talk a bit about what version control systems are why we use them and 0:14 then the basics of how to get set up, 0:18 as well as the most common tasks you'll perform going forward. 0:19 As with many topics in programming, 0:24 there's a great deal you could learn about Git. 0:26 Despite its simplicity, it is an extremely powerful tool. 0:28 However, our purpose over the next few videos will be to give you a high level 0:32 understanding of what you're doing, why you're doing it, and 0:36 then equip you with the skills to begin using it every day. 0:39 In all likelihood, you came here to learn about building apps, and 0:42 we wanna keep you on that path. 0:45 But you'll see very soon, that this detour we're taking really isn't a detour at all. 0:46 It's worth mentioning that if you'd like a more in-depth introduction to Git, 0:52 I've supplied a link below to Treehouse's full Git course, 0:55 which will go into much greater depth than we will here. 0:58 You may not want to take the time to watch it all now, but 1:01 I'd highly suggest watching it at a later date, or bit by bit over time. 1:04 A robust understanding of, and fluency with Git, is more or 1:08 less a requirement for a professional developer these days, but 1:11 again, we just wanna get you up and running first. 1:14 So what is Git anyway? 1:17 Well, it's a version control system or VCS. 1:18 Specifically, it's the most widely used version control system among 1:22 developers today. 1:25 So what's a version control system? 1:26 Well, it's just what it says. 1:29 It controls all the versions of your code or project over time. 1:30 And yes, when I say project, I mean the stuff besides the code too. 1:35 Audio, images, layout, project settings, and everything else. 1:39 There are several other popular VCS's you may have heard of, like Subversion, 1:42 Mercurial, or CVS, but we'll just focus on Git here, as it's a, the most widely used. 1:47 B, how you'll most often share code with collaborators or future employers. 1:53 And C, integrated right into Xcode. 1:57 So it's a natural choice for IOS. 2:00 It's also worth pointing out that Git is not the same as GitHub. 2:02 Git is the system for tracking and sharing all the versions. 2:06 Whereas GitHub is a widely used service for hosting Git projects. 2:09 GitHub definitely isn't the only way to use Git,but we'll be relying on it 2:13 both to teach you about Git, as well as share and save projects going forward. 2:18 As we go, the distinction between Git and GitHub should become much clearer. 2:23 The benefits of a version control system are probably clearest when thinking 2:27 about a coding project, but you can still see how this would be useful even for 2:31 something much simpler. 2:35 Imagine you're writing, editing, 2:37 and rewriting your resume as you look for a new job. 2:38 You'd probably make some general improvements, and 2:40 then depending on the particulars of each job you're applying for, 2:43 you move certain items around, you expound on others, and delete some too. 2:46 Every time you make a change, you save a new version of your Word doc. 2:51 Eventually, you have dozens of slightly different versions of the same resume, 2:55 all saved as separate files with separate names. 2:59 Now the different versions are essentially peers, with no threads to 3:02 connect the changes between them, or when, or why you made those changes. 3:05 Now with a resume, that's probably okay. 3:09 But with a project, especially a complex one with many collaborators, 3:12 you may wanna undo some of those changes. 3:16 Merge two versions together, or easily view all the changes 3:18 without being distracted by all the stuff that hasn't changed. 3:22 Moreover, when your trusty laptop gets left in a taxi or simply goes kaput, 3:25 your files will already be saved in an orderly way, 3:29 even if you hadn't backed it up recently. 3:32 Git, as well as most modern VCS's, act as both a time capsule and a time machine, 3:35 allowing you to record snapshots from different points in time, and 3:40 also fast forward and rewind between them as needed. 3:44 So how does Git manage to do this? 3:48 Well, first of all, Git is a distributed system. 3:50 This is in contrast to the centralized systems we're used to. 3:53 With Git, when you work on a project or a repository, 3:57 as it's called in Git speak, each person has a full copy. 4:00 Rather than being kept in a single location, it's kept in all locations. 4:04 So, you can for example, access the complete project, even when your computer 4:08 is completely offline, which at first might seem counter intuitive. 4:12 When you use GitHub, which is what we'll be discussing in this workshop, 4:16 your project will also be kept there, 4:20 in addition to on each person's local machine. 4:23 Now to be clear, just because everyone has a complete copy of the project, 4:26 doesn't mean that everyone is seeing the same version, or 4:31 that when you make a change it immediately forces it upon your teammates. 4:34 On the contrary, Git allows you to create new branches, so 4:38 that you can safely work in parallel without stepping on each others toes. 4:41 In addition, you have freedom in when you save or commit your changes, 4:45 as well as when you push changes to, or pull changes from the remote repository. 4:49 Now I've just thrown several Git terms at you, like commit and branch, but 4:55 don't worry that we haven't explained them fully. 4:59 We'll do that in the next video. 5:01 For now, let's finish off our introduction with a bit of history and 5:03 a few words of warning. 5:07 Git was created by Linus Torvalds, who is best known as the engineer behind 5:10 the Linux kernel, which became the basis for Gnu, Android, Chrome, and many more. 5:13 As many people know, Linus named Linux after himself, and 5:19 he has often joked that he named Git after himself as well. 5:23 If you don't know, Git is a British slang for a stupid or 5:26 annoying person, like a nastier way of calling someone an idiot or a twit. 5:29 By the way, if you like many people, are unsure how Mr Torvalds pronounces his 5:33 name, you can hear it from the horse's mouth in the link below. 5:37 Torvalds created Git specifically to solve the problems that arise when 5:42 developers collaborate on code. 5:45 In addition, Git does a wonderful job of mitigating the risks, 5:48 both accidental and malicious, that can come with writing shared code bases. 5:51 Now depending on your experience level, 5:55 you may not have written any collaborative code yet. 5:57 But you will before long. 6:00 That said, even when you're working independently, 6:02 Git is definitely still a lifesaver. 6:04 Now for that cautionary tale I alluded to. 6:07 You may have heard the term cowboy coder. 6:10 Well in movies, cowboys may seem like exciting role models, but 6:13 in the programming world, cowboy coding isn't a good thing. 6:16 In fact, it's used to describe a person who knowingly disregards best practices. 6:19 To drive home how helpful using a VCS is, let's imagine you're a cowboy coder 6:24 working on a big project, without any version control system at all. 6:28 So you've been hired to work on an app for a client. 6:33 You start building up the UI, the data model, all that. 6:35 You start adding in features, and after a couple weeks you show it to the client. 6:38 They like what you've done, but 6:41 decide to get rid of one of the snazzy features you added. 6:43 You say okay, delete the feature, and continue working. 6:46 Then a week later at your next client meeting, 6:49 they say they've had a change of heart, and they want that feature back. 6:51 Now you're stuck with having to recreate the feature from scratch. 6:55 If you were lucky, perhaps you saved a few interim copies on your computer, so 6:58 you could find that feature and cut and paste it back in. 7:02 But, how would you remember which version had which feature? 7:05 Also, if it's the kind of feature that requires changes in several files or 7:08 with several assets, it might be really time consuming to find them and 7:12 paste them all back in. 7:15 A VCS would track all of that history for you. 7:17 At your third client meeting, you find out that the project has grown so 7:21 much, other developers will now be joining the effort. 7:24 You'll need to work in parallel on the project, and 7:27 then merge those changes back together later. 7:29 No doubt, some of those changes will have happened in the same files. 7:32 So, how can you tell whose changes to keep, whose to toss, and 7:35 which might need to be carefully spliced together? 7:39 Well if everyone was playing cowboy, you'd probably need to sit side by side and 7:42 go through the project line by line, and discuss all the differences. 7:46 Now I've had to do that, and I assure you it is no fun at all. 7:50 It's also very error prone, and 7:54 a huge waste of time that could be spent creating new features or testing. 7:56 Again, Git, or most VCS's for that matter, can handle this workflow for you. 8:00 It isn't always completely effortless, but 8:05 overall, it will allow you to bring the changes together seamlessly, and 8:07 even when it doesn't, it provides the transparency to work through any issues, 8:10 as well as security, in case of mistakes. 8:14 This was just one example of how life without a VCS is harder in the long run, 8:18 and why developers rely heavily on version control as a part of their daily routine. 8:22 Join me in the next video, 8:27 and we'll talk through some of the most common Git terminology and practices. 8:28
You need to sign up for Treehouse in order to download course files.Sign up