Hey Everybody, in this post you will learn an interesting and very important topic. So welcome to How To Add Code To GitHub Using PyCharm Tutorial. After completing this post, i am pretty sure, you will be able to upload python files on GitHub. So let’s gets started.
Contents
- 1 A Quick Introduction To GitHub
- 2 Getting Started To How To Add Code To GitHub Using PyCharm
- 3 Conclusion
A Quick Introduction To GitHub
If you want to be a python programmer, of course you have to work on project. Now most of the time you have to work in a team, of course you can make a solo project, but if you want to make a big project, you will be having multiple members. Let’s say you have 4 members working on one project. Now you have the option to divide your project on 4 different modules, and you can work on one module or may be you will having one module and multiple people can contribute.
Now what you think, how can you share the code? You are working on a project and 3 other members are working on a project, of course you have to share your files and of course you have to merge them somewhere on a machine. How will you do that?
There are two ways by which you can share your files –
- Mailing Source File – you can share your code in mail.
- Dropbox – You can get a folder and everyone will put those code in this folder, thats how you can share files.
But it is not an efficient way. If you want to share your code, two things should be considered –
- One thing is that you should have merge files.
- The second thing is that you also have to maintain the version. And that can be done with the Git .
Now let’s see just a quick overview of GitHub such as what is github, why we use it etc. so let’s move to next.
What Is GitHub ?
- To understand GitHub, you must first have an understanding of Git. Git is an open-source version control system that was started by Linus Trovalds—the same person who created Linux. Git is similar to other version control systems—Subversion, CVS, and Mercurial to name a few.
- GitHub is a code hosting platform for version control and collaboration.
- It lets you and others work together on projects from anywhere.
Why GitHub ?
- It is always a good idea to keep project on github.
- Because let’s say you are working on a machine and tomorrow you will have to go another city or anywhere and you got a new machine but at that time you have not your project.
- But if you have kept your project on github then you can simply pull your project from github repository on your new machine. You don’t have need to use any online storage or pendrive or other stuffs.
- The next reason to use github is that if you are working in a team, and you and your team members want to contribute same repository then git is a best option for you to work together. You don’t need email or other stuffs like that.
Now i hope you have much understanding about github. Now let’s move towards the main topic of this tutorial.
Getting Started To How To Add Code To GitHub Using PyCharm
In this section, you will learn downloading and installing github on your system, sign up and login to github, creating repository in github and many more. So let’s move further.
Downloading GitHub
To work with github, firstly you need to have download the github setup on your system.
- Now go to this link and download github setup on your machine.
Installing GitHub
Once the download process have done, next you have to install it on to your system. So install it as you usually install any applications.
SignUp And Login To GitHub
To use github, you need to an account on GitHub website. So go to official website of GitHub and create your account. Creating account on github is very simple, you just need to provide some basic informations and your account will be created.
Once the sign up has been done, next you need to have login to github for working further tasks.
Creating Repository
Now you have to create a repository. A repository contains all project files, including the revision history. So let’s see the below image.
In the above image, you can see a new button is available. Click on it and you will be redirected to following page.
Now, you have to fill this form.
- In Repository name, you just have to fill a name which you want to give your repository.
- Next in description you have to fill some description about your repository.
- Next you have to choose Public or private but here you have to choose Public because it is free and Private takes some charges.
- Finally click on Create Repository button. You will get something like that.
Now you can access your repository using command line as well. Here you can see some commands are here.
Creating A New File On Repository
Now your repository is empty, you have to create file here so click on Creating a new file option. This can be any file that means you can have a text file, python file, java file etc.
Now give a file name as you want. Here we are working with python file so we need to enter a python file. And write some code to this file. Here is an example.
Once you have entered your code then next thing you will do is to save this because if you don’t save it, it will not be showed.
But here is a different command i.e., Commit new file. Click on this.
Now you can see, you got your file here.
Now open this file, you will get your code here. But of course, you are not writing your code here. So to write the code you need some IDE. Here i am using PyCharm. So now the question is how will you pull this project on your PyCharm IDE. It’s very easy actually, you can simply do Clone or Download.
You can click on Download Zip, that’s way you will Zip version. you can unzip it and open that project on PyCharm. That’s the first method, but here we will discuss the another method. So let’s move forward.
Creating A Project On PyCharm
Now create a project on pycharm IDE.
Configure Git Executable
Then go to File -> Setting and in Version Control you have some options, choose the Git option to configure the git.
- Now you need to give executable path of git.
Configure GitHub Account
Now go to GitHub
- Here you first need to select Auth type as Password, by default it is Token.
- Then you have to enter login and password of GitHub account and hit OK button.
Pull The Repository
To pull the repository, you have to do following tasks.
- Go to VCS-> Checkout from version control -> Git.
- Here you have to insert url of your repository.
- Then click on Test option.
- Make sure you are logged in to your GitHub account.
- Now the connection has been established with the url successfully.
- Then hit the clone button. After this you can see your repository has been pulled to your PyCharm project.
Changing The Existing Code
Now you can change this code as you want. I am adding following line to my code.
1 2 3 |
print("**********") |
Now run this code, you will see your code is running and giving result but this code is only available on your machine. And that’s why currently version control is not maintaining. If you to achieve version control system, you need to say commit every time. So everytime you commit, you maintain the versions. But here is a new question arises – How to do commit?
Committing The Modified Code
Right click on your project folder then select Git -> Commit Directory. You will get following screen.
- Now you have to add commit message. It should be a logical message because other people can understand it.
- Now click on commit button. But yet it is not stored into remote server.
- In github, here is two thing one is local repository and second is remote repository.
- Everytime you commit, it will saved at the local repository that means if you go back to github website and if refresh it, you can see only the existing lines here
- That means whatever changes you have done on your pycharm, it is not reflected in github website or remote repository.
Pushing The Code On Remote Repository
Now if you want to store your code on remote repository then you have to do following tasks.
- Right click on your project folder then select Git -> Repository -> Push. You will get a screen that have push button, you have to simply click on this button.
- Now if you are doing it first time and you have not logged in to your github repository then it will give you a prompt where you have to enter your username and password.
- Now your code is uploaded into remote repository.
- Now go to github website and refresh your repository page. You will get your updated code.
You can see one line is added to your code.
Conclusion
So guys, its all about the How To Add Code To GitHub Using PyCharm tutorial. It’s always a good idea to store your project on github. Git is the preferred version control system of most developers, since it has multiple advantages over the other systems available. It stores file changes more efficiently and ensures file integrity better. If you have any query then ask here, i will try to short out your problems. And stay tuned with SIMPLIFIED PYTHON for latest and important tutorials.
THANKS