Skip to playerSkip to main content
  • 2 weeks ago
Take my Full Git and GitHub course: https://www.analystbuilder.com/courses/git-and-github-for-data-professionals

VS Code: https://code.visualstudio.com/
____________________________________________

RESOURCES:

💻Analyst Builder - https://www.analystbuilder.com/

📖Take my Full MySQL Course Here: https://bit.ly/3tqOipr
📖Take my Full Python Course Here: https://bit.ly/48O581R
📖Practice Technical Interview Questions: https://bit.ly/46pDqqL

Coursera Courses:
Google Data Analyst Certification: https://coursera.pxf.io/5bBd62
Data Analysis with Python - https://coursera.pxf.io/BXY3Wy
IBM Data Analysis Specialization - https://coursera.pxf.io/AoYOdR
Tableau Data Visualization - https://coursera.pxf.io/MXYqaN

Udemy Courses:
Python for Data Science - https://bit.ly/3Z4A5K6
Statistics for Data Science - https://bit.ly/37jqDbq
SQL for Data Analysts (SSMS) - https://bit.ly/3fkqEij
Tableau A-Z - http://bit.ly/385lYvN

*Please note I may earn a small commission for any purchase through these links - Thanks for supporting the channel!*
____________________________________________

BECOME A MEMBER -

Want to support the channel? Consider becoming a member! I do Monthly Livestreams and you

Category

📚
Learning
Transcript
00:00Hello, everybody. In this lesson, we're going to be taking a look at the basics of Git.
00:04Now, I have several things open on my computer screen here.
00:08First, I have Git Bash open. Go ahead and pull that up on your screen.
00:12You should just be able to search for it and open up Git Bash.
00:15We looked at how to install Git in the last lesson.
00:18So you should have that installed. Just pull up Git Bash.
00:21And it should look something like this, of course, with your information right here.
00:26The next thing that I have pulled up, and I'm on a Windows, is I have my file path.
00:30So I have my file folder. I have file paths here.
00:32So right now, we're just in my downloads.
00:35But we'll be using this as we go on.
00:37And the last thing that I have pulled up right in the background here is Visual Studio Code.
00:42Now, this is going to be our IDE that we are using in the next several lessons.
00:46But you can use any IDE, and you can connect it.
00:49This is just the one that I personally use a lot.
00:51And I think it really integrates well with Git and GitHub later on in this series.
00:57So if you haven't already, I will leave a link down in the description
00:59on where you can download Visual Studio Code.
01:01Again, you don't have to use it. You can use any IDE that you want.
01:04But this is the one that I recommend, and I think that most people will be using.
01:08So here's what we're going to do.
01:09We are going to take a look at Git, and we're going to see kind of where it defaulted to.
01:14Because we just installed it, and Git is on our computer.
01:18But we haven't done anything to it.
01:20But we haven't set it up.
01:21We haven't kind of customized it to our project.
01:24And so we need to do all of these things.
01:26The first thing I'm going to do is I'm going to come right down here,
01:28and I'm going to say PWD.
01:31And this is going to tell us the current file path that it's on.
01:35Now, let's come down here, and we're going to go to my C drive.
01:38And we're going to go down to Users, and we're going to go to AlexF.
01:41This is the current drive, and there it is.
01:43There's .get.
01:44Let me pull this up a little more.
01:47Now, this is my C drive on my computer, and it just has a bunch of old stuff.
01:52This is back when I was creating a lot of Python tutorials and web scraping tutorials.
01:57And as you can see, there's a lot of junk in here.
02:00And so if I come over here and I look at this, I'm just going to say LS.
02:04It's going to take a second because it's going to pull in all these files.
02:08It's going to pull in all these folders, which had a lot of stuff in it.
02:11And so as you can see, this is really messy.
02:14There's so much junk in here.
02:16Honestly, I should go through and delete a lot of this.
02:18But I hold on to it for sentimental reasons, potentially.
02:21And what I need to do is I need to either clear this out and make the C drive really
02:27clean,
02:28or I just need to create a new folder.
02:29And when I'm doing a new project, I usually just create a new folder.
02:34So let's come in here, and we're going to do a new folder here.
02:37I'm going to call this, let's call it AA, just so that it shows up at the very top,
02:42because I have it in alphabetical order.
02:43We're going to say AA get video series.
02:48And so let's go ahead.
02:50Well, we can either refresh right up here, and it should show up right near the top,
02:55at least right here.
02:56It didn't show up, I guess, at the top.
02:58I have too many other ones.
02:59But we have our AA get video series right here.
03:02Let's open this up.
03:04And this is beautiful.
03:05There's nothing inside of it.
03:07This is just, it's lovely, right?
03:09But we don't have access to this just yet.
03:12We need to do something called a change directory.
03:15We need to go in here and say, this is where we want get to be pointed at.
03:20So we're going to do a change directory, a CD, and then we just need to put in here,
03:25this right here.
03:26So I'm going to do a Control-C on this.
03:29But when we come in here, it's different for pasting it.
03:34We have to do a Shift-Insert, just like that.
03:37Actually, I need to put this in quotes.
03:39But I need to do Shift-Insert, put that in quotes, and there we go.
03:44So now you can see right here, there is a new directory, and it's pointing at this file
03:51path right here.
03:52So now we have it in here.
03:53But even if we refresh this, there isn't anything in there.
03:57What we have to do, especially if you're starting a new project, and we're about to start adding
04:01files, and we're about to start coding, and this project's going to last more than a couple
04:05days, maybe weeks or months, we want to capture all those snapshots of all the code that we're
04:10saving and everything like that.
04:12So we need to initialize a repository in here.
04:15So let's go ahead.
04:17We're going to say git init.
04:19That just means initialize a repository.
04:22Let's go ahead and hit enter.
04:23It said initialize an empty git repository at this location.
04:27So now we have this .git here, which means that we now have an empty repository that we
04:33can start adding and committing files to.
04:36So it takes those snapshots of the history of this file path.
04:40And so if we add files to this, and I'm going to show you how to do that in just
04:43a second,
04:44we're going to add files, we're going to add and commit them, and then we'll see how we
04:47can look at our previous history.
04:49So let's do the same thing that we did up here.
04:51We did this ls.
04:54Let's go ahead and look at ls.
04:57And you'll see that there are no files in this file path.
05:00Well, let's change that.
05:02Let's come right over here, and let's go into our Visual Studio Code.
05:06Now, what we're going to do is we're going to come up here to Explorer, but in a second,
05:09we're going to come down here to Source Control.
05:12And this is where git is literally integrated into VS Code, which is really, really nice.
05:18But first, let's open up our folder, and let's go to the project folder that we just created.
05:25That's in Users, Alex F, and then the AA Git Video Series.
05:29So we're going to add this.
05:31And now we have it open, but of course, we don't have any files in it just yet.
05:36And then if we come right here, you can see that now it is connected.
05:41So now we have this master branch right down here connected to this AA Git Video Series.
05:48That's because in our folder, we have a Git repository initiated.
05:53So when we connected to that file path within our Explorer, it picked up the fact that we
05:59are connected to Git already, and it connects to this.
06:01Now, this is going to help us a lot.
06:03We're not going to use this right now.
06:06We're going to do everything within Git, but there is a great UI in VS Code that allows
06:11us to do a lot of what we're about to do in Git.
06:13But I want to take a look at the basics first, and then we'll use VS Code after.
06:19So what we're going to do is we're going to create a new file.
06:21So we're just going to come up here.
06:22You can either say Control-Alt-Windows-N or whatever the shortcut is on your computer.
06:27But let's go ahead and click on a new file, and let's just add a Python file.
06:32Let's keep it really simple.
06:33So I'm just going to add a comment here.
06:34I'll say this is a new file in our first commit.
06:40And we're going to go ahead and save this.
06:42You can do Control-S.
06:43We can save it right in here, and I'm going to rename this.
06:46I'm just going to say first file, first underscore file.
06:51And let's go ahead and save it.
06:52So now we have this file in our folder, and we can see that right here.
06:58We have this first file.
06:59Now, again, there are some things that we're going to look at specifically in VS Code,
07:03but we're not looking at that right now.
07:05Let's come over here, and let's take a look in Git.
07:10So now we're going to say LS.
07:12Now it's going to read in that first file.
07:15It shows that we have a file in it, but if we go and we write Git status right here,
07:22we're going to get some information.
07:23The status basically tells us where things are in the process.
07:27Have they already been added to the Git repository, and therefore we can go back and look at them?
07:31Have they been added but not committed?
07:33So we're going to do that in just a second.
07:35We're going to commit this first file.
07:36We can see on branch master, which is our master branch, we have no commits yet.
07:42We haven't made any commits, so nothing is in our Git repository over here.
07:46So we have an untracked file, our first file.py, but nothing added to commit, but untracked file is present.
07:55So this is our untracked file.
07:56So here's what we need to do.
07:57We have to do two things.
07:58I pulled this up just so we can kind of see it, but right here we have to do two
08:02things.
08:02We're in our working directory, so that's where we're currently at.
08:06We have our working directory, but we have to first add it to our staging area.
08:10Then we commit it, and that's to our local repository.
08:14That's our Git repository, which we can then use to take those snapshots.
08:19So let's first use Git add, and then let's Git commit, and let's see how that works.
08:24So we're going to say Git add.
08:27Now when we get here, you can specify this file path, and you can just say firstfile.py,
08:34and it's only going to add that file.
08:36So if you have like 20 files in here, and you only want to upload the firstfile.py,
08:41you can specify that.
08:42I don't almost ever do that.
08:45I usually just hit period, which means take everything in this file folder,
08:49and we're going to add that if there have been changes made to that file.
08:53So we've made changes to this file, so we're going to hit Git add everything.
08:57And now let's go and hit Git status again.
09:01And now you can see we have a new file.
09:03These are changes to be committed.
09:05We haven't committed it just yet, but we are ready to commit this.
09:09Once we commit this, it will be stored in this Git repo.
09:14And again, we can revert back to this.
09:16So let's come in here, and we're going to say Git commit.
09:21Now, don't make the mistake that I made when I was first doing this,
09:24and just hit enter.
09:25You can do this, but it brings up the separate UI.
09:30And so I don't recommend doing that.
09:31You can still write your message and everything in there.
09:33But we're going to do dash M, which means here's our message for this commit.
09:37So when you make a commit, you have to have a message.
09:39It doesn't have to be a long message.
09:41It can be very simple.
09:42But when you go back in time and you go to those past snapshots,
09:46you can write yourself messages.
09:47And so we're going to say, this is my first commit.
09:52Woohoo!
09:54And that's our commit.
09:55That's our commit message.
09:56Let's go ahead and commit this.
09:58And it says, master, root commit.
10:01This is my first commit.
10:02Woohoo!
10:03One file changed.
10:04One insertion.
10:05Created mode.
10:06And then this right here is the file.
10:09So now, let's look at git status again.
10:12And there we go.
10:13It says, on branch master, nothing to commit, working tree clean.
10:17Which means we haven't made any changes to these files in here
10:21since the last time that we made a commit.
10:24So now that we've made a commit, now we can go and we can look at our log.
10:28So I'm going to say git log.
10:30And now it's going to show us our previous commits that we have made.
10:34And you can see this really long string of numbers and text.
10:37This is our hash, which we can use to revert back to that snapshot.
10:43So this is our kind of a snapshot hash code that you can use.
10:47And so this is actually very important.
10:49This is what you can use to tell git where to point to
10:52when you want to revert back to a previous commit.
10:56Now, we're not doing that in this lesson.
10:57But we'll do it in a future lesson where we'll revert back once we made some changes.
11:02So now let's come right over here and let's go back.
11:05Because before, and it just got rid of it.
11:07But before it said U for untracked, which means it wasn't tracking anything.
11:12And now we can also go into our source control and we can see visually that there is a commit
11:17right here.
11:17And this is just awesome.
11:18When you start making a bunch of commits and a bunch of ads and you start branching and merging,
11:22this little UI down here is actually really helpful.
11:25At least it helps me a lot.
11:27Let's do something really quick.
11:29Let's come back here.
11:30And we're going to make a change to this file.
11:32So I'm going to say this is our code.
11:36And I'm just going to make some really ridiculously simple code.
11:39Let's say I love git.
11:42There we go.
11:43And then we're going to save this.
11:45Control S.
11:46So now we've saved this file.
11:48And now we have a new letter right over here.
11:51It says that this file has been modified.
11:53And so it's giving us a visual indicator that, hey, this has been changed.
11:58It has not been saved.
11:59So if we go over to our source control, we now see that there were changes made to this first
12:04file.py.
12:05It was modified, but it hasn't been committed yet.
12:09So we haven't added this and we haven't committed and it's not saved in our git repo.
12:14Now, just to make this a little bit even more obvious, we're going to add another file.
12:19So again, just add a file.
12:21We'll do text file.
12:22It doesn't matter.
12:22I'm going to say this is a text file for the git series.
12:29That's all I'm writing.
12:30And we're going to save that.
12:32And I'm just going to call this one first text file.
12:38And we're just going to save it as a txt file.
12:40So now that we've added it, now we have this green U.
12:43This means it's untracked.
12:45This file has not been saved in the git repo at all.
12:48And we need to do that.
12:49So again, let's go back to our source control.
12:54And now we have a U right here.
12:55So you'll notice we have some options under here within our source control for each file.
13:01We have open the file, discard these changes, which means we can completely get rid of this,
13:07which we can do.
13:09Or we can stage the changes and then we can commit them.
13:13So let's only stage right now this first file.py.
13:18Now we have it in two separate sections.
13:20One is just the changes have been made.
13:22The other is this one has been added to the staging area, which again, if we come back
13:27down here and we look at this, by adding it to the staging, we just added it right here.
13:34We just did the git add, but just with a click of a button.
13:37We can also unstage the changes or we can add them both.
13:40What we're going to do is we're going to make another commit.
13:42So now we're going to come up here and let's get rid of this.
13:45We're going to make another commit.
13:47So let's commit this.
13:48And it wants a message here.
13:49And so I'm not going to do that because that's not typically what I do.
13:53I'm going to enter my message right up here.
13:55I'm just going to say second commit with updated file.
14:01Now, usually with this message, it should mean something.
14:04You should kind of indicate what you're doing with it or what you've done.
14:08But, you know, that isn't super important at the moment.
14:11Let's go ahead and commit this.
14:13And you'll see right down here, we now have a second commit.
14:16So this is our first commit and then right up here, this is our second commit.
14:19Now, look at this thing right here.
14:22This is our hash.
14:23We can save this or we can copy this using this button.
14:26But if we go up, that hash has completely changed.
14:29And it's also noted that this was saved, who it was, where it was saved and what that commit
14:35message was.
14:36It also will tell us that one file was changed, six insertions and one deletion.
14:41So it gives us some information.
14:42And again, that's something we'll look at in a future lesson about how to look at those
14:46differences.
14:46But if you'll notice up here, we didn't commit this one.
14:50And that's because we never added it to the staging.
14:52So let's stage this.
14:53Let's say this is our third commit with text file.
14:58And let's commit this.
15:00And now we have three commits.
15:02Our first commit, our second commit, which I misspelled with.
15:06That's a shame.
15:08And then we have our third commit.
15:10Now, these are all on the master branch, right?
15:13But in a future lesson, we can create separate branches within our GitHub repository.
15:18And that's going to totally change the game and how we do our workflow and a few other
15:22things.
15:22And we'll get to that in a future lesson.
15:24So we now have these three separate commits.
15:27And in the next lesson, what we're going to look at is how we can revert back to these
15:32previous snapshots or commits.
15:34So I hope that that was helpful.
15:35I'm super excited for the series because we're going to be connecting this to GitHub.
15:39We're going to be saying we can update things and we can clone repositories and a bunch of
15:43other things.
15:43So I'm super excited.
15:44I hope this is really helpful to you guys.
15:47If you like this video, be sure to like and subscribe and I'll see you in the next video.
Comments

Recommended

RareGear
2 months ago