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.
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
You can connect with me here
Top comments (17)
Quick and easy to read intro!
If useful, Github, Gitlab and maybe others also renamed their default branch from
master
tomain
which I found a nice initiative (it was reflected at my workplace back then too)Informative!
Nicely Explained.
If you like my work, then consider buying me a coffee
buymeacoffee.com/SiddhiBh
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
Sure 🎊
nice one
Thank you
Nice blog Siddhi 👍👍
Thank you so much
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. 😄
Thanks for sharing !
nice 2 minutes intro
Thank you
Informative!!
Nicely explained🔥
Thank you
Very nice, thank you!
Thank you