Python for Entrepreneurs Transcripts
Chapter: Source Control and Git
Lecture: Git Repositories

Login or purchase this course to watch this video and the rest of the course contents.
0:01 We had a chance to dabble with some of the basic Git commands on the command line.
0:04 Now we need to do a deep dive into the fundamentals of what a Git repository is.
0:09 You are going to use a Git repository to keep track
0:11 of all the changes in your source code that underpins your business;
0:15 let's say you are developing your application and you are happily hacking along
0:18 in a single source file, just getting started.
0:20 and you've decided "OK, I'm at a good spot, I want to save this",
0:23 so you use the "git init" command, you start adding changes with the "git add"
0:27 and the "git commit" commands and over time,
0:29 you build up file history in your Git repository for that file.
0:33 Now, of course a Git repository wouldn't be very useful if it was only for a single file,
0:37 it's going to keep track of all the changes in your entire project, your entire code base.
0:42 We could have several files or we could have as many files as we need,
0:46 and chances are you are going to have a single Git repository for your entire project.
0:50 And that way, it provides you with the ability to roll back to previous versions of your files
0:55 just in case you break something or just to understand
0:57 where you might have accidentally introduced the bug
1:00 when you were working on something late at night.
1:02 To recap what we did in a previous video,
1:03 we used the "git init" command in order to create a new Git repository,
1:08 that was an empty Git repository; we then added changes with "git add",
1:12 which puts files that we're trying to track into a staging area,
1:15 and then we used the "git commit" command in order to move those files
1:20 that were in the staging area into the permanent Git commit history.
1:24 Now a Git repository contains the entire history of all of your files,
1:28 with commits as pointers to the repository changes,
1:32 let's take a look at what this looks like in practice,
1:35 I've switched over into the Full Stack Python open source Git repository history,
1:39 I have about 1800 commits that I've made over the past four years
1:43 to the Full Stack Python code base.
1:45 We can take a look at the most recent Git commits, with the "git log" command.
1:51 Now this is just showing me in reverse chronological order
1:54 what the most recent changes are that I made to the repository.
1:57 If we want to drill into any of these changes we can use the "git diff" command,
2:01 we can specify two commits and take a look at what the differences are
2:05 between those two commits.
2:06 In most cases you only have to use the first seven characters of the entire commit string
2:10 in order to specify which individual unique commit you want to take a look at.
2:15 Let's try to run this right now.
2:16 The "git diff" command is showing me the files that I actually changed,
2:20 so if we take a look at the third line and the fourth line here,
2:23 about-author.html, we can then glance down and see red where lines were removed
2:29 and green where I added something.
2:31 So in this case it really was just changing some in line CSS styling on the top banner
2:35 and if we press space bar, we are just going to go through more of the changes that were made,
2:40 but it looks like I was doing here was I changed the base template
2:42 and I made some changes to the top banner on the site
2:44 and that cascaded through all the HTML files.
2:47 So if we fly through all the changes here,
2:50 we'll see that all the HTML files that had that banner were changed,
2:52 seeing these changes and then taking a look at the commit messages is super helpful
2:55 for figuring out how changes were made over time to the repository.
2:58 So that's the "git log" an "git diff" commands.
3:01 Typically, you'd have one repository per project when you're working with Git repository
3:05 so I'd say as you are starting you side business, your project,
3:08 just start with the single Git repository and track those changes over time,
3:12 even if you are not working with anyone else, again, this is still really valuable,
3:15 even if you yourself mess something up and then months later
3:18 you need to hunt down what happened.
3:20 Now the one other bit about repositories containing
3:22 all of the changes that you've ever made to the source code,
3:25 is that the repositories can easily be copied and backed up on remote servers and services;
3:30 this is where services such as GitHub and Bitbucket come in.