How to use Git in PyCharm #installation #commit #checkout #reset

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this session is one of the most important videos on your learning path because today you're going to learn how to use git git is a must-have skill for any programmer no matter what programming language you're going to use so let's get ready and begin yesterday in the programming tools of yesterday I explained what get is so if you haven't followed that video please go back to the programming 2 video of yesterday so as I explained yesterday git is a version controlled system it is a software you need to install in your computer and then you connect git to the project you're working on and git will allow you to see and manage different versions of your program so you can see the code as it was at different timestamps before we go ahead and download and install Kit maybe it's a good idea that you go to your terminal in poet charm and type in git there so not in the python console but in the terminal type in git and if you get this error or some other error that means git is not installed so you want to open your browser type in git on Google and then go to the git Dash SCM page and I'm going to show you how to install git on Linux Mac and windows on Linux and Mac it's pretty straightforward all you need to do is this if you are on macaron blue install git But first you need to install home brew in your Mac so search for Homebrew on Google install Homebrew and then run this command that should install git if you are on Linux then do sudo apt get install get so run that command and git should be installed if you are on Windows you should go to this page as I just explained to you git Dash scm.com and go to this button download for Windows you have different files depending on your system but I'll just click this first button click here to download the latest Git Version once the files download you can just click it here or go to the folder where it's downloaded and double click it press yes you can read the license if you like and then press next that will be the path where gits will be installed so I'll press next you can leave the default options as they are and click on next next again I would suggest to change this option from use Vim to use notepad plus plus or use notepad I'm selecting use notepad so this is a text editor which gets uses by default Vim is harder to use so for you as a beginner I would suggest to use a simpler text editor such as notepad although we're not going to really use this default editor because we're going to use get inside powercharm inside our own IDE therefore this optioner is really not important here so click on next the first option is fine let's get decide and click on next here this is important you really want to select this the default option gets from the command line and also from third party software so we're going to use git through pageon therefore this is important click on next next again use the open SSL library next next next next again git credential manager is fine next and finally install and then I'll click on finish these are some release notes I'll close that and then I'll go to the pycharm terminal I'll close the terminal and open it up again and then I want to try get press enter if that didn't do anything then you might want to restart poacher so exit and open it again go to the terminal type in git press enter and this time we didn't get that error so we needed to restart poet charm so if you got these messages that means the git command is now recognized by Windows right so now we have git installed in our system we restarted Python and the next step is to integrate git with our pycharm project to do that you want to go to VCS this menu here and then go to the first option enabled Version Control integration so there are different systems there I mentioned this yesterday gets Mercurial sub version we're using gitsu I'm pressing on selecting get here click OK and immediately I got these file names colored in red that means git is now integrated so what does this color mean anyway well this color now means that these files are not included in the version control system so git is not tracking these files we need to do something to track them to add them to the Version Control registry also called a repository so now Gates has some folders somewhere where it keeps track of the files you have so it has a list of files it sees what files you have here was folders you have so it keeps track of them and you we need to tell git now keep track of these files to do that you want to do something called a commit operation you can execute a commit operation using this green tick mark in here so press that once I press that that is going to open this window here on the sides of pycharm and down here you see this ticking cursor this is blinking it's asking us to enter some description for example initial commit now this is known as the commit message here you want to write something meaningful and short it is recommended to be the length of a normal sentence so you want to describe what you did so what we're doing here is we are creating a timestamp we did some changes so we created the initial project and we created timestamp and then we can go back to this time stamp later on and as the first message of the first time stamp we usually write initial commit and so then you want to press on Commit however when we press on Commit we get this message select files to commit up here you'll see this checkbox on versioned files if you expand this you're going to see all the files you have in your project directory so these are this git signal file which we're going to talk about later this was created by gits automatically and then we have our python files functions.py main.py there are some files also from pie charm automatically created some settings files and the settings file actually actually are things that we don't need to include in the Version Control System we're only interested to include the files of our projects so what I want to do now is I want to suspend this I will not check any of these files I just want to minimize this and then go to the project directory and then I want to right click over vent go to get and then go to add to get ignore and then press on that add to dot git ignore now this is asking us if we want to create a git ignore file so we want to press on create and now you see that I dot git ignore file was created and it's here in the project directory you see dot get signal now this is saying if you want to add this dot kit ignore file to git you want to press on ADD so what I did is that I added this van folder to the dot gate ignore file that means this folder is not going to be tracked by the version control system so gits will ignore this folder similarly we can ignore that hidden dot idea folder which had all those power charm settings files so you don't want that as well and if you like you can also ignore the bonus folder you just name the folder name there and so on if you want to ignore a file for example to deuce.txt you write the name of the file of course we don't want to ignore to this.txt because that is part of our project bonus is not part of the project those are separate files I don't want them in my git repository so again you want to go back to that commits window now you can go either here at this tab or you could go to that button again commit and it will take you here now you see that dot git ignore is checked by default and that is because we press that add button here when we created dot kit ignore pycharm asks if you want to add that gets ignore we press on ADD that's why this was checked by poachon to add the other files you can either check them in here one by one or or you can click on this always add option here and those will be checked by default I'd like to do things manually so I'll just check everything that I I know what I'm doing so functions.py yes main.py yes to dos.txt yes and finally we're ready to press that commit button so press on Commit here you want to specify a username so just choose something such as or did and put your email address here and then press on set and commit now this password and email address are only asked to the first time you will not get asked again in the future press on sets and commit and we are done so I see this message here four files committed initial commit so we committed dot get ignore main.py functions.py and to dot txt what that means is all these four files now are tracked by get that means if I go to main.py and I add something for example above this it is now print function I want to add another print function print the time is below let's suppose that what I have just added is a new feature to the program right I added a label that is a feature let's say so anytime you add features you want to do a commit so you want to record that Milestone therefore I want to go to that commit button again the green tick mark press it this window will show now in here you'll see that main.py is automatically checked so git automatically found out that we made a change to this file so the next time we commit as we're doing now get notices that we have done a change between the last commit and this commit and you want to leave that checked and you want to write a message at time label feature for example so this is how messages should look like it's recommended to use present tense or verbs try to start your your sentences with a verb so at time label feature that is what you did in this commit and press commit right then you can close this tab by pressing that tab there and then if you go to this git tab down here bottom left press it you're going to see all the commits you have done in your project so if you press in one commit for example I press over at time label feature here on the right you're going to see the files you have changed in that commit so that was main.py if I double click main.py it's going to show me side by side the current file here on the right and the previous version of that file here on the left so you see here we don't have that print function but here we have it so in this view you can see the differences but now what if you want to go back to the state of the program as it was in the initial commit so if I press on initial commits you see that main was like that there was no that feature here which prints out it is time that's new label so how can you go back to one timestamp to one commit that is what I'm going to show you now so let me close that here is the main.py file as it is right now so you see main.py it's not from the revision it's the actual file and there are two commands which you can use to go back to a previous commit one is checkout and one is reset git checkout and git reset when would you use git checkout and when would you use get reset let me demonstrate you git checkout first to do a git checkout you can right click over the commits you want to go to so you want to retrieve the program as it was in that commit right click and then go to checkout revision click that now you're going to see that that print function which was somewhere in here has disappeared so now you're looking at the previous version of the program as it was when you did the initial commit here you'll see this yellow tag with an exclamation mark after it that tag showed up when I press on that checkout option so that means this is now the current version of the program the thing is this add time label feature is still a commit and it is still standing there so the check out command is not the actual command you should use if you want to permanently go back to this commit so checkout is simply to quickly see the state of the program as it was so you can also execute the program if you like and you're going to see the output of this current state oh but if you want to have the permanent changes then you want to use a reset command so checkout is simply to check a previous version and then go back to the master Head silver head is the latest commit so now we are currently in here you see the tag but then you want to click right click here after you have seen that previous state of the program and then you want to go to checkout and then go to master you'd see that now the yellow attack went back to the first commit so now you see that print function is here again the time is below now the reset command is different if you right click over initial command commits and you go to reset current Branch to here then you want to go to heart and if you press reset now that commit disappears so basically you go to the previous state of the program permanently therefore check out is particularly useful especially now that you are learning so each day you can make a commit and you have all these commits recorded for each day so then maybe you want to go back to a date just to check out the code you know see it run it and then you can check out the latest Branch again so how often do you do commits in real life well it depends you'll get used to that with experience but basically if you add something and it works so you you make some changes you run the code it works then you make a commit the changes could be changes of the existing codes or adding new code so both could require a commit basically during a day you might have several commits depending on how much you code and that's it so if I close parcharm now I exit I open it again and of course the commits are still there so in this git tab you can access the commit we have only one commitment now because we reset it to this commit so all other commits are disappeared the other commits Above This commit are disappeared so that's what you learned today to wrap it up you learn the commit command the checkout commands and the reset commands I know it's very confusing in the beginning you have many questions many things you are not clear of but don't worry about that because you'll fill in those gaps as we program through the course that's why we have many apps we're going to build many apps and we're going to use Git along them so you'll see me how I work in different scenarios and by the end of the course you'll have a very solid skill set to use git independently on your own and understands all its features one more thing before we close the video yesterday you heard me mention GitHub in the programming tool of yesterday I didn't introduce you to how to use GitHub today because I wanted to focus on git so git is the version control system that means it tracks the changes on our local computer and GitHub is the hosting platform is a cloud-based service where you upload your code to a server to keep it as a backup and as a point to collaborate with others you can share your code using GitHub now we didn't cover GitHub today because we want to take things step by step so today we simply worked locally our code changes are tracked locally on our computer tomorrow we're going to synchronize the code to GitHub so that you know how to use both git and GitHub so with that thanks a lot for following this and I'll talk to you later see
Info
Channel: PythonHow by Ardit Sulce
Views: 22,489
Rating: undefined out of 5
Keywords:
Id: rOkaHoOD3g4
Channel Id: undefined
Length: 19min 33sec (1173 seconds)
Published: Sun Nov 27 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.