How to use git and GitHub with PyCharm and any other IntelliJ IDE

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone in this video i just want to show you how you can use version control git and integrate python with github using this ide however you don't have to use pytharm but you can use any intelligent intellij ide and the same you can follow the same procedure and the same methodology okay so the first thing that we need to do is to create a new project with pycharm if you haven't already created one so we're going to create a new project here by clicking on this button here we're going to create a pure python project this is the location of our project and we're going to call it the project here and we're going to use the python interpreter which is installed on my computer however if you want you can also create a virtual environment which is a safe option if you want to make sure that you keep track of all the pen for the dependencies and all the version of the dependencies okay but in this case it's going to be a simpler overview and we're going to just have a look at python 3.8 you can be a beginner for this video don't worry if you've never heard about git and github before this is the right video for you and i'm going to try to explain everything step by step so we're going to create a main dot pi welcome script and we click here on create if you are not prompted with that window before but you are just prompted the pycharm open in this view so you can click here on file new project pure python and then create a new project here same window as we were before okay so this is the python project python file that pytharm has already created for us which has a good practice is called main dot pi so this one contains our main file let's see what happens if you run this file we can run this file by clicking here on the green triangle but at the same time you can press shift f10 and we're going to run it here it's going to print i pi chart i don't want that to say i by term i want to say that hi federico by my name so shift f10 and now is printing my name so great we have a python project a python code that is actually working now what i just want to show you is how you can use the version control directly inside python how can you do that you just have to go here at the top bcs local history okay maybe the first yeah local history show history and it's actually going to show us all the changes that we've made you remember that we started with this file so we started with this ipy charm now we change it to i federico let's go and change something else we're going to say print how are you again shift f10 we can see the changes how are you vcs local history show history is telling us that now we have added this function here how are you okay so here we change the from by charm to federico and now this file also contain print our u because this is actually just showing us only the last file the last version while here shows us step by step so here we change from pie chart to federico and here we change the from uh we have actually added this function also our you okay so this is okay i mean if you're only working locally in your computer you don't really need to have git but if you want to start sharing your code with some other collaborators and you want to start leveraging github so you can share the code and safely store it on github on their servers so even if your computer crashes you don't have any issues a good practice is to initiate a git repository on your computer how can you do that so you just have to go here vcs import into version control create a git repository okay where do we want to create it well in the same directory that we are actually working so here github desktop github project project and here we want to have initiate our github repository let's press ok as soon as we create a gita repository a python arm is telling us you are missing the getting or file so what is the git ignore file the git ignore file is a file that we need to add when we have a git project to tell git which file we want to keep track of and which file we don't want to keep track of so let's go here create git ignore we're going to use a template let's type python because our is a python project so let's click here generate this has generated a file for us and is asking that would you want to add the file to git of course we want to add it so as you can see you can see it's red now that we press add we're keeping track of this file and now it's green another thing that we need to add since we are using pytharm is idea okay so we want to also ignore these configuration file which is automatically created by python okay now is keep telling us something because what would you like to do with inversion file okay like this one main dot pi do we want to keep track of it or not well at the moment we are not because can you see is he red so what we need to do is right click git add okay so now that message has disappeared main now we are keep tracking of me so let's go and do the first commit vcs commit or alternatively ctrl k i'm going to use ctrl k so let's see what we have changed we have created this git in our file okay we are happy with it we just use a template and now we have added mail okay so mean now this is the first commit so what is exactly a commit well we're going to store in the history that at this stage at 9 52 of this day this file looked like this and it was working so we were happy with these changes okay so we're going to call it first commit okay you can just type any message that you want and then ctrl enter or clicking here is going to do the commit okay now let's play a bit let's go in main and let's add a new line a print statement okay how are you and where do you live okay so now we've added a new question shift f10 let's test yes it's printing where do you live everything is fine we are happy with the changes but we can see that the file now is blue why is blue the reason why is blue it means that the file was previously tracked using it but now we have made a new change and where is the new change here is in green can you see because it's a new line we haven't changed the previous uh um the previous line that we already there we just have added a new line let's actually try to change this line instead how are you doing okay so now this all appears blue and white i mean now it all appears blue because it thinks that we have changed both lines actually in fact it doesn't even recognize that we have added a new line after this but let's see if uh [Music] yes here it works as you can see we haven't changed this line so here we have changed from high to a low so this line was already here so it's blue but this line here is completely new okay so it's green so that's the main difference and the color code so let's press ctrl k again and let's commit the changes so we say we change i to hello and how did a new question here we can see all the things that we change in fact we say i to hello in blue in green the new question okay commit how do we keep track of all these committed we have done super simple here at the bottom there is a git button let's click here let's go on log and here we can see the first commit in the first commit we created we added this new file main and git ignore in the second commit we only change main no we did not change git ignore and if you click here we can see all the changes that we made okay another thing that i want to show you is that sometimes you don't want to sync with git or your file so let's create a file which is called secret see red okay in this file we are going to add our password so do we want to add the following file to git cancel we are going to type password and let's say that this is the password that we use to connect to our database okay so we don't want this file and not even by mistake or by chance that is a track with kit we just want to have it on our computer because we are going to need this password to access the database but we don't want to sync it with git so how do we do that we go in the git ignore file here and we add the new file read secret okay to buy so now this file will actually turn yellow let me see or let's do actually ctrl k ctrl k as you can see this file now is yellow why is yellow because we are not keeping track of it and in fact as you can see here when we are doing the commit we can only see the changes in getting norm okay so we have um we are ignoring secret dot buy okay so as you can see here the only change that we had to commit was this change here but not this file here and that's what we want because now when we go to main here we can and this is probably not the best way of naming this file here but i just wanted to show you how you can do that because for instance here and of course you don't want to do that but you can do import secret okay and here for instance or actually say from secret from secret import password and here we can do print password shift f10 as you can see here is my password of course you don't want to do that but you will have a function here which is going to be connect to a database for instance which this function here is going to connect to a database and connect the connector to the database we'll have some it will be a function which you can use there are connectors to mysql all the type of database which will require a password so instead of printing the password here you will pass this function this variable inside here okay so now we're happy with our file we have imported our password we are not sharing our password with anyone we haven't uh commented committed these things so let's say importing a password so let's commit that so that's the only change that we have done we have also changed i mean this is just a space okay commit okay everything is working our file is working we could even send it to our peers or our collaborator to work on now we also want to start working on a new function but we haven't tested it yet so what do we do what is the best practice well the best practice is not to change the main file as we're being doing here but to create a new branch what is a new branch a new branch is a copy of this repository but we're going to work on it so we're not going to affect the master code so let's say that the master code is the code that is working on your computer is windows or mac software that is stable and is installed on your machine but then developers want to test a new feature so they create a new branch they create new features one they have tested them then they send them to master okay and then you're going to receive a notification for instance on your computer update the app update the software and so forth and this is the same thing that we want to do okay how do we do that we go here at the bottom okay or here vcs get branches okay we type new branch which is the same as going here new branch and we call it the development development okay we created this branch here so now we are no longer in master but we are in development okay so let's do a ctrl k here no change is detected and let's go here let's type a new function so my function my function is going to take two inputs a and b and it's going to return a plus b okay so this is the new function that we have created and the last test that is working print my function and 2 comma 4 shift f10 should be 6 exactly 6 so everything is fine and let's change and let's commit the changes okay so we have created this new function my function and we are testing new function okay ctrl commit now control enter has committed the changes and everything is fine the problem is that now we have our working function but is not in master and of course this was super simple to test but think about if you have created a long function so we want to for sure to test it before but now we have this function which is in development but if you go back to master and now we go back to master we can go here at the bottom master checkout well the function is not here so how do we copy and for across shall we copy it and paste it manually no of course no we actually use the power of git so we go vcs here git merge changes git merge what do we want to merge we want to merge into master merge into master we want to merge development okay because we have our function that is working so we merge and this is my function okay now we have all the changes also implemented in master okay so now we are fine because we have our changes that before we are not seeing to master also in master now we can go back here development and we can delete this branch because we do not longer need it okay so let's go back here and get we can see that in master we have also this new we never did this commit in master okay testing new function but we got it from that branch okay so now we have practically learned everything so now we know how to use git we know how to use version control and again if you want to use version control is super powerful because here you can see all the changes that you have done to the files and you can also keep track with this menu if you prefer but now that we have used git we can see everything here we are ready to ship our code and to sync it with github okay so let's open uh let's open the let's open the browser here we are so we're going github repository new okay so you just have to go in github we call it my example so let's call it you [Music] version control it's going to be public okay we don't want to add any file at the moment we just want to keep it clean because we already have the getting our file created and everything is fine we just to create a repository okay so now github is going to create a repository for us and the only things that we need to know is this okay so this is to link our repository here local on computer to github how do we do that vcs okay get um remotes okay we add one here and we add name origin as you can see it's called origin url we just have to copy the url okay it's checking the url of course you might be asked to put the password i've already set it up with the password you might be asked to just log in with your github credential of course you need to do that and what you need to do is to push the changes okay so here we push our changes so here it shows us all the local commit first commit all the things that we have gone through and we are going to push okay now let's see pushing here at the bottom once it's done we can go here refresh and we have our file get ignore and main and of course we don't have secret okay now let's assume last thing that i want to show you let's assume that our friend is has also access to this repository goes inside main here and it actually changed our function here and it uh it changes as our function so from my function we discuss with him and we say yeah i work on it we didn't want to say a plus b but we change to a minus b okay so e of course you don't really have to see this part but i just want to show you that someone else can change the code on github and how do you keep track of that so our friend makes the change commit the message and the message is changed from class to minus commit the changes okay and now our file has changed okay so if we go here and we go into and we go into our code okay sorry okay yeah it wasn't just rendering properly if we go into main now we can see that from a plus b now is a minus b but we don't have this change here reflected on our local machine so how can we get that those changes well using it okay so first we do git update project okay we update the project is asking us merge incoming changes into the current branch okay so we merge it and now we can see that our function has changed okay so everything is fine if both change both changes were done we didn't change anything here on our code okay but let's assume that something happens and we change both so our the two file now are synced okay now we define a variable which we're going to call it x equal to three okay and we commit our changes and we so we commit our changes okay we say define it x we commit our changes and then we push our changes to github okay so now is pushing let's refresh this file here x equal to three everything is fine everything is in sync now our friend what happen is that our friend goes here and change this to 30 instead of three and commit these changes at the same time we change this variable here from three third three to twenty three okay now you will see that the two things are not matching any longer so here there is 30 and here is 23 okay so what is going to happen let's see what happens let's do update project merge incoming changes in the current branch okay we're getting an error we're getting an error why because originally was three okay from remote from github we've changed it to 30 but from our local file okay is 23. so who is right well we need to decide we need to decide we accept right we accept left we accept a bit of both because i mean there could be many things that are conflicting with each other okay in this case we think our friend is right so we click here and we accept right okay so now as you can see our valuable has been changed to 30 okay i really hope you find this video useful please ask any question down in the comment below and please consider liking this video and subscribing to my channel if you found this video useful and please also write some other some comments down below if you would like me to create similar videos about pie chart thank you very much for listening
Info
Channel: Federico Tartarini
Views: 11,289
Rating: undefined out of 5
Keywords: pycharm github repository, github pycharm, pycharm github, github pycharm setup, github pycharm tutorial, how to use version control in pycharm, version control in pycharm, pycharm version control tutorial, pycharm github push, how to enable git in pycharm, pycharm version control, pycharm github pull request, version control git, version control github, version control in python, pycharm python tutorial, track changes in pycharm, How to use pycharm on windows 10
Id: dBMHuIWbF_k
Channel Id: undefined
Length: 22min 49sec (1369 seconds)
Published: Thu Nov 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.