Learning git is always a plus point. It has many advantages ,some of them are as follows :
- You can contribute to open source projects.
- You can collaborate with your friends to make a project.
- Contributing to open source will open new doors of opportunities for you.
In this part , I will be covering how you can push your code to github from your local computer/laptop. So let's get started.
You have to install git inorder to run these commands. Link to install Git
After that you need to open a github account and make a empty repository over there so that you can push the code there.
Now think of a buffet system. The first step is to clean the place and arrange the food on the tables. The same step is followed here , first we have to make it a git repository and then we can start pushing the code.
Now if you want to convert your local project/folder into a git repository, you have to first initialize it to a git repository. The command for it is
Consider the same example of buffet system . After arranging food we ask the people to form a line. So this is what we are doing here as well. We are asking our code to stay in the staging area. The command for this is
git add .
. here represents that we are adding all the files in staging area, you can explicitly mention the file name as well.
If we consider the example of buffet system again , so before taking the food we check the status, if it's available yet or not. So sometimes we need to check the status of our files , if they are all in staging area or not. The command for the same is
Now if you consider the buffet example, it's time to add food to our plates. So in this step we are saving the files permanently to our git history. This is called commiting the code. The command for the same is
git commit -m "initial commit"
-m means the commit message . You always have to specify a commit message while committing the code.
If you consider the buffet example, if you don't know which food is served where then how will you eat the food, you need to know the destination. Same happens with our code, if you want to push code ,you need to specify where? The command for the same is
git remote add origin <url of the repository on github>
origin is just a name for the destination url.
So here we are specifying the destination.
Now it's time to eat our food . Yeah🎊🎊. Finally we reached to our last step wherein we will be pushing our code to the destination. The command for the same is
git push origin master
Here we are pushing the code to origin which is our destination and we are pushing it on master branch. I will be talking more about branches in the next part of the series.
So, these were the steps to follow so that you can make a new repository and push the code from your local computer. On the next parts of the series we will be talking about branches, issues, pull requests and how to contribute to an existing project. Your feedbacks are much appreciated.
If you like my work consider buying me a coffee here
You can connect with me here