What is Git and how to use it to save your work!
Greetings class, today I bring a video all about version control with Git *** Chapters: 00:00 - Introduction: Why We Need Version Control (VCS) 01:00 - Mandatory Prep: Installing Git 03:23 - Getting Started 07:28 - The Daily Grind: Saving Your Work 11:42 - Working Together: Sharing Changes 13:21 - Time Travel and Investigation: Branches and History 17:44 - Outro *** * * * About my avatar The base avatar model was provided by ニバンボシ堂 - Nibanboshido - [https://nibanbosi.booth.pm/](https://nibanbosi.booth.pm/) The clothes were made by Akabane - [https://twitter.com/akabane_vr](https://twitter.com/akabane_vr) * * * Music All of the music in this stream comes from NCS - [https://ncs.io/](https://ncs.io/) * * * GET MY GAME ON STEAM NOW: [https://store.steampowered.com/app/1621210/Nemithia__Tale_of_the_Legendary_Saviors/](https://store.steampowered.com/app/1621210/Nemithia__Tale_of_the_Legendary_Saviors/) WEBSITE: [https://professor-leo.com](https://professor-leo.com) BLUESKY: [https://bsky.app/profile/omegaleo.pt](https://bsky.app/profile/omegaleo.pt) HELP SUPPORT MY HOBBY: [https://ko-fi.com/omegaleo](https://ko-fi.com/omegaleo) -- Watch live at [https://www.twitch.tv/professorleo](https://www.twitch.tv/professorleo) -- Watch live at https://www.twitch.tv/professorleo
Transcript
Greetings class. Welcome back to the Greetings class. Welcome back to the classroom. As always, I'm Professor Leo classroom. As always, I'm Professor Leo classroom. As always, I'm Professor Leo and today we are tackling the invisible and today we are tackling the invisible and today we are tackling the invisible superpower of modern software superpower of modern software superpower of modern software development, the version control system development, the version control system development, the version control system or VCS for short. More specifically, the or VCS for short. More specifically, the or VCS for short. More specifically, the one and only Git.
one and only Git. one and only Git. Now, imagine this scenario. You're Now, imagine this scenario. You're Now, imagine this scenario. You're working on the greatest final project of working on the greatest final project of working on the greatest final project of your life. Let's call it Project your life. Let's call it Project your life. Let's call it Project Awesome. and you decide to make a big Awesome. and you decide to make a big Awesome. and you decide to make a big change. You hit save. Then disaster change. You hit save. Then disaster change. You hit save. Then disaster strikes. The whole thing breaks. What do strikes. The whole thing breaks. What do strikes. The whole thing breaks. What do you do? Panic. Yeah, that's one way to
you do? Panic. Yeah, that's one way to you do? Panic. Yeah, that's one way to handle it. But no, you time travel to a handle it. But no, you time travel to a handle it. But no, you time travel to a point where your project still works. point where your project still works. point where your project still works. Git commands are here to save your time Git commands are here to save your time Git commands are here to save your time throughout your development workflow.
throughout your development workflow. throughout your development workflow. Git is essentially a toolkit for common Git is essentially a toolkit for common Git is essentially a toolkit for common tasks like managing your code changes, tasks like managing your code changes, tasks like managing your code changes, handling branch management, and handling branch management, and handling branch management, and reviewing history. It's how professional reviewing history. It's how professional reviewing history. It's how professional teams keep track of everything.
Before we start traveling through time, Before we start traveling through time, we need the time machine. Unlike some we need the time machine. Unlike some we need the time machine. Unlike some other programs, Git doesn't usually come other programs, Git doesn't usually come other programs, Git doesn't usually come pre-installed with your operating pre-installed with your operating pre-installed with your operating system. So the first step is getting system. So the first step is getting system. So the first step is getting your Git installed on your computer.
your Git installed on your computer. your Git installed on your computer. Uh this may change depending on your Uh this may change depending on your Uh this may change depending on your operating system. In the case of operating system. In the case of operating system. In the case of Windows, you need to go to the Git Windows, you need to go to the Git Windows, you need to go to the Git website and download the installer, but website and download the installer, but website and download the installer, but for systems like Linux, Git is most for systems like Linux, Git is most for systems like Linux, Git is most likely in your package manager. For likely in your package manager. For likely in your package manager. For example, in Ubuntu or in Debian, all you
example, in Ubuntu or in Debian, all you example, in Ubuntu or in Debian, all you need to do is sudo appget install git need to do is sudo appget install git need to do is sudo appget install git and it will find the installer. and it will find the installer. and it will find the installer. Uh if your version of Ubuntu and Debian Uh if your version of Ubuntu and Debian Uh if your version of Ubuntu and Debian is one of the latest ones, of course, is one of the latest ones, of course, is one of the latest ones, of course, because really old versions of the because really old versions of the because really old versions of the system might not have it in the package system might not have it in the package
system might not have it in the package manager. manager. manager. With that out of the way, let me try to With that out of the way, let me try to With that out of the way, let me try to install in Windows since it's the one install in Windows since it's the one install in Windows since it's the one I'm using at the moment. So, I just need I'm using at the moment. So, I just need I'm using at the moment. So, I just need to go to Git. Click on the first link to go to Git. Click on the first link to go to Git. Click on the first link that appears. Be careful for scam that appears. Be careful for scam that appears. Be careful for scam websites. Some might appear. Always websites. Some might appear. Always
websites. Some might appear. Always check that it's g--scm.com. And then we press download from Windows. And then we press download from Windows. Click here to download the latest Git Click here to download the latest Git Click here to download the latest Git for Windows. That's correct. Save. for Windows. That's correct. Save. for Windows. That's correct. Save. And then once it's downloaded, we just And then once it's downloaded, we just And then once it's downloaded, we just open it and it will start installing.
Hit next. Next, Hit next. Next, hit next. Basically, just hit next hit next. Basically, just hit next hit next. Basically, just hit next several times unless you want to decide several times unless you want to decide several times unless you want to decide any custom options for Git. any custom options for Git. any custom options for Git. But usually the default options work But usually the default options work But usually the default options work really well. So nothing to worry there.
Okay. And with that git is now Okay. And with that git is now installed. So now that we have git installed, let's So now that we have git installed, let's move on to the next part. Let me create move on to the next part. Let me create move on to the next part. Let me create a folder on my desktop which are going a folder on my desktop which are going a folder on my desktop which are going to call uh git project for example.
Okay, we have this folder created and if Okay, we have this folder created and if I right click I should have git bash I right click I should have git bash I right click I should have git bash here. In the case of any other system, here. In the case of any other system, here. In the case of any other system, you'd mostly want to CD into the folder you'd mostly want to CD into the folder you'd mostly want to CD into the folder by via terminal or you'd want to for by via terminal or you'd want to for by via terminal or you'd want to for example open the folder in terminal example open the folder in terminal example open the folder in terminal since Windows operates in a different since Windows operates in a different
since Windows operates in a different way. It's open git bash here. You can way. It's open git bash here. You can way. It's open git bash here. You can also open in terminal in other uh also open in terminal in other uh also open in terminal in other uh Windows installations like Windows 11 or Windows installations like Windows 11 or Windows installations like Windows 11 or a very customized Windows 10 install. Uh a very customized Windows 10 install. Uh a very customized Windows 10 install. Uh but in this case it's the bare minimum.
but in this case it's the bare minimum. but in this case it's the bare minimum. So yeah. Uh okay. Now that we have this So yeah. Uh okay. Now that we have this So yeah. Uh okay. Now that we have this done, there are two options that we can done, there are two options that we can done, there are two options that we can do. We can start fresh or we can clone. do. We can start fresh or we can clone. do. We can start fresh or we can clone. I'm going to start fresh. And after that I'm going to start fresh. And after that I'm going to start fresh. And after that I'm going to explain how to clone a a I'm going to explain how to clone a a I'm going to explain how to clone a a project.
project. project. [clears throat] [clears throat] [clears throat] So to start fresh, all we need to do is So to start fresh, all we need to do is So to start fresh, all we need to do is be in our folder in the terminal and say be in our folder in the terminal and say be in our folder in the terminal and say get init. get init. get init. This basically creates an empty git This basically creates an empty git This basically creates an empty git repository repository repository and creates the hidden folder that's and creates the hidden folder that's and creates the hidden folder that's git. If I go here and say view hidden git. If I go here and say view hidden git. If I go here and say view hidden items, here it is. There's the git
items, here it is. There's the git items, here it is. There's the git folder. This folder is basically a folder. This folder is basically a folder. This folder is basically a folder that stores all your folder that stores all your folder that stores all your configuration and logs for your configuration and logs for your configuration and logs for your repository itself. And yeah, basically repository itself. And yeah, basically repository itself. And yeah, basically you have your git repository created.
you have your git repository created. you have your git repository created. This will track everything that happens This will track everything that happens This will track everything that happens inside of this main folder. inside of this main folder. inside of this main folder. So for example, if I create So for example, if I create So for example, if I create uh testtxt, uh testtxt, uh testtxt, it will detect that a file was added it will detect that a file was added it will detect that a file was added later on. I'll explain it when we get later on. I'll explain it when we get later on. I'll explain it when we get there.
there. there. So yeah, by default, git creates the So yeah, by default, git creates the So yeah, by default, git creates the main branch as master. main branch as master. main branch as master. Uh so do be careful with this because Uh so do be careful with this because Uh so do be careful with this because some systems may use main as the main some systems may use main as the main some systems may use main as the main branch and not master.
branch and not master. branch and not master. This can be changed and I'll explain it This can be changed and I'll explain it This can be changed and I'll explain it later on. Okay. Okay. With option A done, we now move to With option A done, we now move to With option A done, we now move to option B which is to clone a project. option B which is to clone a project. option B which is to clone a project. Say for example your project already Say for example your project already Say for example your project already exists in the cloud somewhere be it exists in the cloud somewhere be it exists in the cloud somewhere be it GitHub gt uh gitlab you can clone it and GitHub gt uh gitlab you can clone it and
GitHub gt uh gitlab you can clone it and to basically do that all you need to do to basically do that all you need to do to basically do that all you need to do is basically go to the repository you is basically go to the repository you is basically go to the repository you want. So for example let me go on GitHub want. So for example let me go on GitHub want. So for example let me go on GitHub and copy one of my own repositories and copy one of my own repositories and copy one of my own repositories that are publicly available.
that are publicly available. that are publicly available. Let me see. Let's go grab uh the Unity Let me see. Let's go grab uh the Unity Let me see. Let's go grab uh the Unity toolbox for example. toolbox for example. toolbox for example. I'm going to go here and where it says I'm going to go here and where it says I'm going to go here and where it says code, I'm going to basically press it code, I'm going to basically press it code, I'm going to basically press it and press copy URL to clipboard.
and press copy URL to clipboard. and press copy URL to clipboard. Now if I cdv to the upper directory Now if I cdv to the upper directory Now if I cdv to the upper directory and do get clone and then the URL I and do get clone and then the URL I and do get clone and then the URL I copied copied copied it will essentially make a copy on my it will essentially make a copy on my it will essentially make a copy on my system of the whole project.
system of the whole project. system of the whole project. Uh in some cases you may need to Uh in some cases you may need to Uh in some cases you may need to configure the authentication credentials configure the authentication credentials configure the authentication credentials for the specific repository if the for the specific repository if the for the specific repository if the repository is private or part of an repository is private or part of an repository is private or part of an organization organization organization that can be explained in a later video that can be explained in a later video that can be explained in a later video going more in depth on the other aspects going more in depth on the other aspects
going more in depth on the other aspects of Git, GitHub and everything else. Now, let's talk about the absolute most Now, let's talk about the absolute most important daily workflow, saving your important daily workflow, saving your important daily workflow, saving your changes. This process involves three changes. This process involves three changes. This process involves three steps. First, you check your status. steps. First, you check your status.
steps. First, you check your status. Before you save, you need to know what Before you save, you need to know what Before you save, you need to know what you've changed. So, by doing git status, you've changed. So, by doing git status, you've changed. So, by doing git status, it will show you the status of your it will show you the status of your it will show you the status of your working directory and of the staged working directory and of the staged working directory and of the staged files. So, when you add, change or files. So, when you add, change or files. So, when you add, change or delete files, git can show you the delete files, git can show you the delete files, git can show you the differences. For example, if I do get
differences. For example, if I do get differences. For example, if I do get status, status, status, uh, uh, uh, apologies, I was in the wrong directory. apologies, I was in the wrong directory. apologies, I was in the wrong directory. Okay, it get status. Okay, it get status. Okay, it get status. It will say unttracked files test.txt It will say unttracked files test.txt It will say unttracked files test.txt and then says use git add the file name and then says use git add the file name and then says use git add the file name to include it in what will be committed.
to include it in what will be committed. to include it in what will be committed. So that's the next step which is the So that's the next step which is the So that's the next step which is the staging area. Git doesn't automatically staging area. Git doesn't automatically staging area. Git doesn't automatically save every change you do. You have to save every change you do. You have to save every change you do. You have to tell it which changes are ready for the tell it which changes are ready for the tell it which changes are ready for the permanent record. We use GitHad to move permanent record. We use GitHad to move permanent record. We use GitHad to move files to the staging area. Think of
files to the staging area. Think of files to the staging area. Think of staging as polishing your essay before staging as polishing your essay before staging as polishing your essay before handing it in. You can stage one file handing it in. You can stage one file handing it in. You can stage one file with git add and the file path. Or if with git add and the file path. Or if with git add and the file path. Or if you want to stage everything recursively you want to stage everything recursively you want to stage everything recursively from the working directory, you can use from the working directory, you can use from the working directory, you can use git add and then a period at the after git add and then a period at the after
git add and then a period at the after the ad. the ad. the ad. And basically that's it. So for example, And basically that's it. So for example, And basically that's it. So for example, if I do get add if I do get add if I do get add and now get status changed to be and now get status changed to be and now get status changed to be committed new file test.txt, committed new file test.txt, committed new file test.txt, it went it saw that test.txt DXT had it went it saw that test.txt DXT had it went it saw that test.txt DXT had been added and was basically unttracked been added and was basically unttracked been added and was basically unttracked and added it as a staged item.
Once the changes are staged, we create a Once the changes are staged, we create a commit. A commit is your snapshot in commit. A commit is your snapshot in commit. A commit is your snapshot in time. It's a permanent record of the time. It's a permanent record of the time. It's a permanent record of the state of your code. You always include a state of your code. You always include a state of your code. You always include a message explaining what you did. For message explaining what you did. For message explaining what you did. For example, get commit dash m for message example, get commit dash m for message example, get commit dash m for message and between co quotes I say added a test and between co quotes I say added a test
and between co quotes I say added a test file file file and for example something else. Okay, it and for example something else. Okay, it and for example something else. Okay, it will also say that my identity is will also say that my identity is will also say that my identity is unknown. So first I need to configure my unknown. So first I need to configure my unknown. So first I need to configure my identity. For that we do the commands identity. For that we do the commands identity. For that we do the commands that are shown on the screen.
that are shown on the screen. that are shown on the screen. user email. Let's say it's my email and get config dash global user.name let's say let's say like so. like so. like so. Okay. Now if I go grab the message Okay. Now if I go grab the message Okay. Now if I go grab the message there it is. Oh, wait. But I made a a there it is. Oh, wait. But I made a a there it is. Oh, wait. But I made a a typo in my commit message. How do I fix typo in my commit message. How do I fix typo in my commit message. How do I fix it? Okay, let me fix it real fast by it? Okay, let me fix it real fast by it? Okay, let me fix it real fast by doing get commit doing get commit doing get commit dash dash m for message again and say
dash m for message again and say addit addit addit test file without the 31 at the end. test file without the 31 at the end. test file without the 31 at the end. There's another way to do this which is There's another way to do this which is There's another way to do this which is without the dash m at the end. without the dash m at the end. without the dash m at the end. This basically opens uh text editor. This basically opens uh text editor.
This basically opens uh text editor. So if I do So if I do So if I do QA QA QA oops okay this case I need to close because okay this case I need to close because I'm not familiar with the specific one I'm not familiar with the specific one I'm not familiar with the specific one that git bash uses. So yeah, no worries that git bash uses. So yeah, no worries that git bash uses. So yeah, no worries about that. about that.
about that. But in essence, we've committed our But in essence, we've committed our But in essence, we've committed our changes into the repository and all we changes into the repository and all we changes into the repository and all we need to do now is basically share our need to do now is basically share our need to do now is basically share our changes. Okay, now that we are ready to changes. Okay, now that we are ready to changes. Okay, now that we are ready to share our changes, all we need to do is share our changes, all we need to do is share our changes, all we need to do is first tell which remote repository we first tell which remote repository we first tell which remote repository we need to point to uh from our current
need to point to uh from our current need to point to uh from our current directory because this is an initialized directory because this is an initialized directory because this is an initialized git folder. By default, if you clone a git folder. By default, if you clone a git folder. By default, if you clone a repository from the internet, it will repository from the internet, it will repository from the internet, it will point the remote to the point the remote to the point the remote to the basically the place where you cloned the basically the place where you cloned the basically the place where you cloned the the project itself. In my case, it's the project itself. In my case, it's the project itself. In my case, it's different because the remote is empty at
different because the remote is empty at different because the remote is empty at the moment. So, in my case, I already the moment. So, in my case, I already the moment. So, in my case, I already created a repository in GitHub because created a repository in GitHub because created a repository in GitHub because my OBS kind of crashed while I was my OBS kind of crashed while I was my OBS kind of crashed while I was recording this part.
recording this part. recording this part. But it's simple to redo it. Basically, But it's simple to redo it. Basically, But it's simple to redo it. Basically, you press this plus button here and say you press this plus button here and say you press this plus button here and say new repository new repository new repository and basically fill in the repository and basically fill in the repository and basically fill in the repository name, description, configurations, etc.
name, description, configurations, etc. name, description, configurations, etc. and just create repository and it will and just create repository and it will and just create repository and it will show like this. show like this. show like this. Now we can basically just follow the Now we can basically just follow the Now we can basically just follow the command that is listed down here. push command that is listed down here. push command that is listed down here. push an existing repository from the command an existing repository from the command an existing repository from the command line. Nowadays, most code hosting line. Nowadays, most code hosting line. Nowadays, most code hosting platforms already show up this command.
platforms already show up this command. platforms already show up this command. So, it makes it easier for you to do it. So, it makes it easier for you to do it. So, it makes it easier for you to do it. So, I'm going to do get remote add So, I'm going to do get remote add So, I'm going to do get remote add origin and point it to my repository. origin and point it to my repository. origin and point it to my repository. And now I can both pull and push my And now I can both pull and push my And now I can both pull and push my changes to the repository itself.
changes to the repository itself. changes to the repository itself. Okay, now for the part where git feels Okay, now for the part where git feels Okay, now for the part where git feels like time travel. It allows us to manage like time travel. It allows us to manage like time travel. It allows us to manage separate lines of development named separate lines of development named separate lines of development named branches and review every step of our branches and review every step of our branches and review every step of our journey. You can switch to a specific journey. You can switch to a specific journey. You can switch to a specific branch using git checkout and then the branch using git checkout and then the
branch using git checkout and then the branch name or you can create a brand branch name or you can create a brand branch name or you can create a brand new branch and instantly switch to it by new branch and instantly switch to it by new branch and instantly switch to it by running git checkout-b. running git checkout-b. running git checkout-b. In this case, I'm going to do it for the In this case, I'm going to do it for the In this case, I'm going to do it for the main branch.
main branch. main branch. get checkout dashb main get checkout dashb main get checkout dashb main and there we go we switch to the br the and there we go we switch to the br the and there we go we switch to the br the main branch if I do get kit status main branch if I do get kit status main branch if I do get kit status on branch main to commit on branch main to commit on branch main to commit and basically that's it we switch to the and basically that's it we switch to the and basically that's it we switch to the main branch now I can basically push my main branch now I can basically push my main branch now I can basically push my changes into the origin repository in changes into the origin repository in
changes into the origin repository in this case the github project by doing g this case the github project by doing g this case the github project by doing g push dash u origin main dash u basically push dash u origin main dash u basically push dash u origin main dash u basically says upstream uh branch is origin main says upstream uh branch is origin main says upstream uh branch is origin main so points my current branch to the so points my current branch to the so points my current branch to the origin main branch which is the github origin main branch which is the github origin main branch which is the github repositories main branch repositories main branch repositories main branch so if I do this
so if I do this so if I do this say Yes. Okay. In this case, uh I need Okay. In this case, uh I need permissions, but it would basically show permissions, but it would basically show permissions, but it would basically show you a progress bar for the push. you a progress bar for the push. you a progress bar for the push. [clears throat] [clears throat] [clears throat] And in the case of someone else doing And in the case of someone else doing And in the case of someone else doing changes to your branch, you could just changes to your branch, you could just changes to your branch, you could just do get pull and it would pull the do get pull and it would pull the do get pull and it would pull the current uh changes in the branch itself.
current uh changes in the branch itself. current uh changes in the branch itself. In this case, I need to set a public key In this case, I need to set a public key In this case, I need to set a public key which we can do in a separate video. which we can do in a separate video. which we can do in a separate video. But yeah, besides that, you have a But yeah, besides that, you have a But yeah, besides that, you have a multitude of other commands that you can multitude of other commands that you can multitude of other commands that you can run to basically review your history.
run to basically review your history. run to basically review your history. For example, git log. For example, git log. For example, git log. Git log basically shows you the commit Git log basically shows you the commit Git log basically shows you the commit message history. Say for example message history. Say for example message history. Say for example uh let me do branchb development development switch to it um get checkout never mind switch to it um get checkout never mind switch to it um get checkout never mind silly me get checkout d-b silly me get checkout d-b silly me get checkout d-b and let's say for example I'm going to and let's say for example I'm going to and let's say for example I'm going to create another file dev dash test
create another file dev dash test create another file dev dash test and basically connect it and basically connect it and basically connect it commit d-m commit d-m commit d-m addersdev test file. addersdev test file. addersdev test file. Okay, Okay, Okay, let me go into the git log. And now you let me go into the git log. And now you let me go into the git log. And now you have the new commit message on top. have the new commit message on top.
have the new commit message on top. Now we can do a really funny thing. Let Now we can do a really funny thing. Let Now we can do a really funny thing. Let me check out back to main me check out back to main me check out back to main and do git diff to development deleted file mode index. Okay, shows a deleted file mode index. Okay, shows a change which is the dev test.txt. Uh in my case on the local branch that Uh in my case on the local branch that I'm on that file doesn't exist. So it I'm on that file doesn't exist. So it I'm on that file doesn't exist. So it appears as deleted file.
appears as deleted file. appears as deleted file. But if I want to do get merge But if I want to do get merge But if I want to do get merge development updating fast forward and it says one updating fast forward and it says one file change, zero insertions, zero file change, zero insertions, zero file change, zero insertions, zero deletions. deletions. deletions. And now if I do get log, And now if I do get log, And now if I do get log, it's also on this branch.
it's also on this branch. it's also on this branch. Basically, get merge allows you to merge Basically, get merge allows you to merge Basically, get merge allows you to merge the branch you want that has new changes the branch you want that has new changes the branch you want that has new changes into your current one. uh sometimes into your current one. uh sometimes into your current one. uh sometimes there may appear some get conflicts but there may appear some get conflicts but there may appear some get conflicts but those can be resolved mostly those can be resolved mostly those can be resolved mostly immediately.
immediately. immediately. So yeah that's basically how we manage So yeah that's basically how we manage So yeah that's basically how we manage our history in git. So there you have it our history in git. So there you have it our history in git. So there you have it the absolute basics of commanding git. the absolute basics of commanding git. the absolute basics of commanding git. You now know how to install the tool, You now know how to install the tool, You now know how to install the tool, start the project, save your progress start the project, save your progress start the project, save your progress and share your work. So you can and share your work. So you can and share your work. So you can basically develop with other uh people
basically develop with other uh people basically develop with other uh people in your project or if it's an open in your project or if it's an open in your project or if it's an open source project basically with anyone source project basically with anyone source project basically with anyone that's participating in it. that's participating in it. that's participating in it. Remember git commands are designed to Remember git commands are designed to Remember git commands are designed to save you time. Practice these basic save you time. Practice these basic save you time. Practice these basic commands and soon version control will commands and soon version control will commands and soon version control will feel like second nature.
feel like second nature. feel like second nature. That's all for today class. If you That's all for today class. If you That's all for today class. If you enjoyed, don't forget to like, enjoyed, don't forget to like, enjoyed, don't forget to like, subscribe, and comment down your subscribe, and comment down your subscribe, and comment down your feedback. and what else you want to feedback. and what else you want to feedback. and what else you want to learn.