Git Series - Part I
Tags: git, opensource, beginners, tutorial
Published: 2022-01-17 08:54:30

Learning git is always a plus point. It has many advantages ,some of them are as follows : 

1. You can contribute to open source projects. 
2. You can collaborate with your friends to make a project. 
3. 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](https://git-scm.com/)
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. 

## 1. Initializing a git repository 

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 
```
git init
```

## 2. Adding the code to staging area.
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 .
```
The `.` here represents that we are  adding all the files in staging area, you can explicitly mention the file name as well.

## 3. Check the status of your files
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 

```
git status
```

## 4. Permanently save your changes 
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"
```
Here `-m` means the commit message . You always have to specify a commit message while committing the code. 

## 5. Specify the destination where you have to push 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>
```
Here `origin` is just a name for the destination url.
So here we are specifying the destination.

## 6. It's time to push the code 
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](https://www.buymeacoffee.com/SiddhiBh)

You can connect with me [here](https://siddhi-244.github.io/LinkTree-Clone/)