Python for Entrepreneurs Transcripts
Chapter: Digging Further into Git
Lecture: Git Staging and Committing

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Now that we're familiar with the "git status" command, we can start adding files to our Git repository,
0:07 Git has a two step process for committing files, the two step process requires us to add files and then commit them.
0:13 First we'll visualize the "git add" and "git commit" commands, and then we'll see an example on the command line.
0:19 Let's say we've got a pretty typical Git repository on your local system, it's got a bunch of files and subfolders with files within them.
0:25 In most repositories there would be a README file, maybe an app.py, something that contains your Python code,
0:31 and of course you want to make some changes to these files, so you open them up in your text editor, you make the modifications that you need to,
0:36 in this case we'll say that README.md and app.py were modified. Now what happens when you run the "git status" command?
0:43 Assuming that you have at least one commit in your Git repository, you'll have a commit hash, this commit contains the most latest file changes,
0:50 excluding the ones that you just made to README an app.py. So when we run the "git status" command,
0:55 it will say that there is untracked modifications to README an app.py. The first step for us to get these added to a new commit,
1:03 is to run the "git add" command and point to README.md and app.py. If we run "git add" with these two files, then the staging area will be updated,
1:13 and if we run "git status" again, these files are not yet committed but they are part of the staging area and ready to be committed.
1:19 The next step would be for us to run the "git commit" command, we don't have to specify specific files with the "git commit" command,
1:26 because, it's just going to take whatever is in the staging area, it's all or nothing, when we run "git commit" and we give it a commit message,
1:33 it will create a new commit and that commit has a specific hash, so for example let's say our new hash is 12ab0f1.
1:42 Now this is actually just the shortened version of the full commit hash,
1:45 the full commit hash is a much longer length, which we'll see in just a moment, finally, if we run the "git status" command again,
1:51 it's going to say that there are no modifications to any files, because the modifications that we made to README
1:56 and app.py have been committed to our Git repository. Let's see what this looks like with an example project.
2:02 I'll run through an example of how I use the "git add" and "git commit" commands, as part of creating the Full Stack Python open source project.
2:09 Don't worry about falling along for now, we'll go through an example with the course demos,
2:13 Git repository in the next video, this example is just to give you an idea of how these commands fit together.
2:19 I'm already in the Full Stack Python project and we can use the "git log" command to see what the latest commit is,
2:24 I mentioned a moment ago that the hash was actually a part of a much longer hash, this is the full hash for "git commit";
2:31 however the last seven digits are typically enough to identify a unique commit
2:35 within a Git repository, and most recent commit was done on December 19th when I added some new NoSQL resources. We're going to add another commit now.
2:44 However, there aren't any changes that we need to commit, I am going to modify one of the files and regenerate the site, so that we have some changes.
2:52 I'll use a text editor of my choice to open up one of the pages, which is the change log.
3:03 I was fortunate enough to cross the 800,000 reader mark for the year, so I'll add a little note about that in here.
3:16 So now this one file is modified, so if we type "git status", it will show us that this one file is not yet staged to be committed,
3:22 however, I don't want to just commit this one file I also want to regenerate the site so that new HTML files are created from the markdown.
3:30 In order to regenerate the site, I add a shortcut command, I just type "m" and it runs a makefile, which handles everything for me.
3:36 And now there should be three files that are modified. The HTML file that gets generated and then the original markdown source file,
3:44 now, we can add these three files, I am going to change into the root directory where all and change-log.html are located
3:51 and then I'll run the "git add" command with period, period means add any files in the current directory or subdirectories
3:57 for a "Git repository", there is one flag you should know about, in case you're deleting files and that would be the -A flag,
4:03 this includes everything when you're adding files, including deleted files which are not normally added unless you specify the -A argument.
4:13 If you already added files to the staging area, you can continue to add them over and over again, and it won't change anything,
4:18 and it won't commit them until you actually use the "git commit" command, let's do that now. We are going to use "git commit"
4:23 and we'll use the "-m" flag in order to specify a message on the command line. Now we've added and committed some files, and if type "git status",
4:36 it's going to say there is nothing to commit and we can continue to work on new files. So that's an example of how I use the "git status", "add"
4:44 and "commit" commands together to work on full stack Python and Byte Size Chunks.


Talk Python's Mastodon Michael Kennedy's Mastodon