DEV Community

Cover image for Git Series - Part I
Siddhi Bhanushali
Siddhi Bhanushali

Posted on • Edited on

Git Series - Part I

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
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
Enter fullscreen mode Exit fullscreen mode

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 .
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Top comments (17)

Collapse
 
kimdontdoit profile image
kimdontdoit

Quick and easy to read intro!

If useful, Github, Gitlab and maybe others also renamed their default branch from master to main which I found a nice initiative (it was reflected at my workplace back then too)

Collapse
 
vdk150202 profile image
Vaibhav Korlekar

Informative!
Nicely Explained.

Collapse
 
siddhi244 profile image
Siddhi Bhanushali

If you like my work, then consider buying me a coffee
buymeacoffee.com/SiddhiBh

Collapse
 
morphzg profile image
MorphZG • Edited

Thanks for sharing. Will follow you. Would like to read more about workflow and branching. When i view history of my commits there is only one log of merging branch with main. I work solo, every time i branch, do some work and than merge i cannot see that in history. There is only regular commit messages.

Edit: github.com/MorphZG/python_projects... view commit history around day 15

Collapse
 
siddhi244 profile image
Siddhi Bhanushali

Sure 🎊

Collapse
 
koppasseryratheesh profile image
koppassery

nice one

Collapse
 
siddhi244 profile image
Siddhi Bhanushali

Thank you

Collapse
 
samrudhipatil51 profile image
Samrudhi Patil

Nice blog Siddhi 👍👍

Collapse
 
siddhi244 profile image
Siddhi Bhanushali

Thank you so much

Collapse
 
trishiraj profile image
Trishiraj

Might also make an honorable mention to "git diff" to cross check on the changes that's been made before all the modified files are staged for the commit. 😄

Collapse
 
siddhi244 profile image
Siddhi Bhanushali

Thanks for sharing !

Collapse
 
midhunz profile image
Midhun

nice 2 minutes intro

Collapse
 
siddhi244 profile image
Siddhi Bhanushali

Thank you

Collapse
 
mrudulkolambe profile image
Mrudul Kolambe

Informative!!
Nicely explained🔥

Collapse
 
siddhi244 profile image
Siddhi Bhanushali

Thank you

Collapse
 
progmac profile image
progmac

Very nice, thank you!

Collapse
 
siddhi244 profile image
Siddhi Bhanushali

Thank you