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


Talk Python's Mastodon Michael Kennedy's Mastodon