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