Python for Entrepreneurs Transcripts
Chapter: Source Control and Git
Lecture: Using the Git CLI

Login or purchase this course to watch this video and the rest of the course contents.
0:01 We've got all the boring first-time configuration, the downloading and installing, all out of the way...
0:06 And now we are going to dive into just getting comfortable with the command line,
0:09 now there is going to be a few concepts here that are going to be unfamiliar, we're just going to flex our fingers a little bit
0:14 and get used to typing in some of the commands that are common in Git. Swap with command line and now we are going to create a new directory.
0:23 So type in "mkdir" if you are on Mac and Linux, or "md" if you are on Windows,
0:30 and we'll just call this "project", so we just got a generic project name
0:34 and we want to make sure we're in a new directory so there is nothing in there.
0:39 Create a new file, now on Mac and Linux again, you can just type "touch", you can say "",
0:48 or you can just open up the file and actually edit it directly. We've got an empty readme file, so if we were going to take a look
0:54 at what's in this readme file, there's just nothing in there, so this is a good time where we say "I've got a blank file, I've got my first file,
1:00 I'm just going to create a Git repository, I want to create it from step one."
1:05 We are going to use the "git init" command, I-N-I-T to initialize a new Git repository. Now our file is completely untouched.
1:16 In fact, it's not a part of this Git repository, we can use the git status command and it will tell us exactly which files are currently being tracked
1:24 and which are not being tracked, now since we haven't added any files to the Git repository,
1:29 there is just nothing in there, and it tells us there is a single untracked file, that's of course.
1:35 We want to add this file to our Git repository now there are two really important commands when it comes to adding files
1:41 and the separate concept called "committing". We can run "git add" and now it won't give us any output
1:50 but that is actually now in a staging area, saying hey this is a new file,, that I am supposed to somehow handle,
1:58 it's in this limbo zone where it's actually not been committed to the repository, so the repository is not keeping track of changes to
2:05 but if we type "get commit", it will now be committed to the repository, so the repository will track the changes of this file going forward,
2:16 it will see what the current status is and what's in the file right now, and then it'll track every change that happens to it, in the future,
2:23 every time we add and then commit that file again to the repository
2:27 what happened is it opened up our editor, now if you configured your editor like I did, I set Vim as my editor, so it opened up Vim,
2:33 and if you say your editor, it will pop open your editor and it will say
2:35 hey I need a message, just tell me what's the reason why you are adding this file, and this allows us to see why we changed files over time,
2:43 so in this case, it's our first commit, I'll just say adding initial file to Git, nothing too complicated, I'll save that and then I'll quit out.
2:54 Now our file has been added and now committed to our Git repository, so if we say "git status", nothing to commit,
3:04 in fact, our readme file is now a part of our Git repository's history.
3:08 Now that we have a single file in our Git repository, we can use a new command - "git log";
3:14 "git log" tells us every commit that is happened in reverse chronological order it will give us the last several commits we've made to this repository,
3:21 so over time we're building up commits so these are like you can think about them as like check points if you play video games,
3:27 basically just where we've said hey I want to save my progress. Now let's say we want to modify the readme file, we can say let's open this up,
3:35 we'll say "Woohoo, I'm learning Git!", now we can save this, and now when we type "git status", it's going to tell us that readme has been modified,
3:47 git knows there are changes to that file and we can use the command "git diff" to find out what those changes are.
3:56 So "git diff" on a specific file will tell us the difference between the version that is currently in the repository
4:05 and this version that has not been committed is the single line, "Woohoo, I'm learning Git!"
4:10 That's super useful for seeing what files have changed and exactly how they've changed,
4:15 between when we committed last and when we've been modifying our files since then.
4:20 The same commands that we used earlier - "git add" and "git commit" allow us to say: "Hey I want to set another checkpoint for my Git repository."
4:28 So we can say "git add", again, we can see "git status" - it's been modified,
4:35 and we can say "git commit" and this time, I am just going to specify "-m" so instead of going into my editor I'm using a shortcut,
4:45 I'm saying "git commit" and I'm saying, just passing a message, "second change to file", and that's not really a great commit message,
4:53 we'll talk a little bit more about what a descriptive commit message would be in the future, but we'll just use that one for now, I'll save that,
5:00 and now when we take a look at "git status", we can see nothing to commit again,
5:04 working tree clean and if we take a look at the "git log", we've got two commits, in our Git repository, so that's pretty awesome,
5:12 now we can see over time how we've been changing our files and when you have thousands of files,
5:17 in a typical project that's really useful to be able to go back and change things or go back to see what you've changed over time.
5:24 I want to just recap a few of the commands that we used "git init" is the command that we used to actually create a new Git repository,
5:32 since we already have a Git repository here, this won't do anything, it'll say "hey, just reinitializing it."
5:37 But it won't change anything that we've done there, we still have the same status, the same Git log, "git init" - so "git init" creates a new project,
5:46 "git status" tells us which files have been modified or which files are waiting to be committed into the repository
5:53 that are waiting in the staging area, "git log" gives us the commit history over time, we have "git add", which will add a new file to a staging area
6:03 and we have "git commit", which then commits all the files in the staging area into the repository.
6:12 So that's a crash course on a few different commands, now the great part about this is if that went way over your head, no problem,
6:18 we are going to dive into each one of these commands and we'll explain a lot more about all this stuff,
6:23 but I just wanted you to get familiar with some of the basic commands that you can use in order to work with Git.
6:28 You may have noticed, we keep talking about this concept of a Git repository, Git repositories contain all of the changes that you have made
6:35 to all of the files in your Git project over time. We'll talk a lot more about Git repositories next.

Talk Python's Mastodon Michael Kennedy's Mastodon