PyCharm Version Control w/ Git & GitHub | Basics in 12 Minutes | Updated 2024

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we're going to take a look at pycharm version control and how we can use pycharm together with github version control is super helpful because it allows you to track your changes and in addition to that you can also revert to older versions of your code whenever you want to but perhaps the greatest advantage of using version control is that you can allow multiple people to work on one code base to explain all this we're going to create a new project so we're going to go on new project and then in the window that opens up we're just going to leave everything as it is create a name for this and press create now that we have a new project the very first thing i want to show you is the local history so let's go ahead and make a small change to this file by writing print hello world after you do that you can go ahead and right click and then press on local history and show history and what you can see here is pretty helpful because it gives you this nice side-by-side view of the changes that you've made so now if i make another change to my file such as write the word by underneath the word hello and then go back to my local history i can see all the changes that i've made in the left hand column and if i want to go back to one of those previous versions i can simply right click on one and press revert and as you can see the word by world that we wrote a moment ago has already disappeared moving on the next thing we're going to look at is how to create a git repository to create a git repository all we need to do is we need to press on vcs then we need to press on create git repository and then we can choose where we want our git repository to be created by pressing ok we can then confirm our selection now there are a couple of things that i want to bring to your attention first the user interface has changed slightly because we have the git commands and in addition we have a new menu that's called commit we'll look at that in more detail in just a moment the other thing that i want to point out is that we have created a git repository in our directory that we specified before if you want to see this git repository all you need to do is you need to right click on the project then you need to press on open in and then explorer and if you now look at this folder that you saved the git repository in you can see that we have a dot git file and this is the repository we just created a moment ago now let's say for some reason you don't need version control and you want to go back to the old user interface in that case all you need to do is press on file then go to the settings and after that in the version control window you can press on the get icon and press on none and after you apply this change you'll see that the user interface has gone back to the state that it was in before we created the git repository now if you want to sign back into the version control all you need to do is press on the same window and then press on git and then click on apply and the user interface has changed back to what we had it a moment ago the next thing that i briefly want to touch upon is the color coding of the file at the moment you can see that the main.pi file is colored in red the reason for that is because we've not yet added it to our git repository so we've not yet added it to the version control and what this means is if you go to the commit tag you'll see that any changes we make to the main.pi file will not be recorded so what that means is if i create another print statement with a text by world underneath then this change won't appear under the default change list on the left hand side in order for this file to be under version control all you need to do is right click in the window and then go to git and add and as soon as we make this change you'll notice two things happen the very first thing is that the main.pi file turns green which means that it now is under version control and the second thing is that if you look in the commit tab under default change list you'll see this file pop up and you can see all the changes that we make to it as you can see here we have these two green highlighted print statements that we've added to our editor but we've not yet committed these changes to our git repository when we talk about committing a change all we mean by that is we take the change that we've made in the editor and add it to our git repository to commit what we currently have in the editor we need to select the changes we want to commit and then add a commit message such as initial commit and then press on the commit button once we have committed the changes you'll see that the color of the file turns gray and this means that the version that we have in the editor and the version we have in our git repository are identical now if we were to make any other change to this file by for example adding the line print by world then you'll see that the file turns a blue color and that means that we have uncommitted changes but you'll see if i choose these changes from the default change list and then go ahead and commit this again our file turns gray again indicating that the version in our git repository and the one in our editor are identical again now the question that you might have is where is all of this stored where is this committed to and the answer is quite simple if we go back to our project and open this project in the explorer we can navigate over to the dot git repository and it is exactly in this repository where all the things that we just committed are stored the actual file we had in the editor for example is stored in the objects folder in a compressed version and the file type is native to the git repository so we can't just go ahead and open it in the notepad for example alright so now i want to show you some of the coolest features that you have at your disposal whenever you use version control so first of all let's say that you've been making a couple of changes to your code but then you notice hey my code isn't working anymore i want to roll back to my previous version if you've not committed any changes yet all you need to do is you need to right click on your file under the default change list and press on roll back and then press on roll back again and you'll see that we've restored the file version that we had a moment ago another pretty cool thing that you can do is you can go to the git tab at the very bottom of the screen then press on log and then you will see this green line and this green line shows you all the commits that you've made so let's add another print statement saying by world and then add the initial commit and add a number to it after that we choose which changes we want to commit from the default change list and then commit this change you will see that this change has now appeared in this line and if you press on one of the earlier commits and then press on show differences you'll see the differences of the current file that you have opened in the editor and the file that existed when you sent the commit if we go back to the line we can right click on one of these dots and we have the possibility to create a new branch branches are really helpful because they allow you to make changes to your project without affecting the functionality of the main project code and once you've finished making changes and tested them in the branch you can merge the branch back into the main project alright so up until this point we've had a bit of a look at what version control allows us to do when we use it on our local machine however there is a bit more to this because imagine your laptop gets stolen or your computer goes broken then in that case you would lose your project and that is precisely the reason why we like to use remote repositories and one way to make use of a remote repository is to use github and so now let's have a look at how we can use version control in pycharm using github so of course the first thing that you're going to need is a github account but once you have one you can go to file settings and then under the version control tab you'll find a tab called github and in this tab you can set up your github account to work with pytron you can do this by simply clicking on the plus icon in the bottom left corner and clicking on add then you can choose what way you want to log in with i'm going to choose login via github that's easier afterwards a browser window will open up asking you to enter your password and authorize github and once you go through this process you'll see that your github account plops up as the very first entry in this window over here and just to make sure that your github is properly linked make sure to click apply before you exit this window now what you can do is you can go to the get tab and then you can press on github and share project on github after that you'll get the small window that says share project on github you can give your repository a name and a description if you want to and then you can press share now if you want to make this project private and you don't want anyone who visits your github page to see this project you can press on private let's just make a private for now we can also make a public later on on github and then we can press share and once you've done that you have successfully shared your project on github so now you can actually go over to your github account and you'll see that you have your project uploaded in github and now after you've shared your project in a remote repository on github you have all the advantages of version control in a remote repository that means even if your computer gets lost or broken you won't lose your project and in addition to that you can share your project or even collaborate with other people remotely on one project so now let me show you how you can commit a change to your remote repository so in other words all we want to do is we want to make a change to our code in the editor and we want to make sure that this change is also saved in our github repository the first thing we need to do is we need to make sure that we're using the remote branch so if you go to the bottom right hand side it says git branch and when you click on it you can choose what branches you want to commit to now we have several local branches but we also have this remote branch which is the github branch we had made earlier so you want to go ahead and click on the remote repository and then press check out now whenever you make a change within the editor and then press commit and then push your commit to the remote repository you'll be making this change directly within github so right here i'm going to change the word buy to hello then i'm going to choose these changes and press commit and push then a window will open i'm going to press push again and now these changes will be pushed to the origin which is our remote repository so now if we go ahead and open up github you'll see that these changes are there after i refresh the window you see that now it says hello world and not by world anymore alright i hope this video helped you out if it did then make sure to leave a like on this video it helps out a tremendous amount and make sure to subscribe to my channel to stay up to date and if you have any topics that you would like me to cover then make sure to leave a comment down below i'll be answering all of them see you in the next video
Info
Channel: Max on Tech
Views: 43,500
Rating: undefined out of 5
Keywords:
Id: 8ZEssR8VTKo
Channel Id: undefined
Length: 11min 51sec (711 seconds)
Published: Wed Jun 22 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.