The only 5 git commands you need to get started

The only 5 git commands you need to get started

So no more procrastination

·

5 min read

Nowadays, you would have heard a lot about OSS (Open Source Software) and mentorship programs like Google Summer of Code, Outreachy, LFX mentorship, and many more. If you are starting in tech or a professional you do not want to miss these opportunities 😀. But to use these opportunities, you need to know the basics of some version control systems. The most widely used VCS is Git.

What is Git and GitHub?

Git

Git is a distributed, open-source version control system (VCS) that enables you to store code, track revision history, merge code changes, and revert to earlier code versions when needed

Okay, so imagine you have a big box of toys. Sometimes you want to play with a particular toy but can't remember where you put it. Maybe you left it in your bedroom, or perhaps you left it at your friend's house.

Git is kind of like a big box of toys for computer programmers. They use it to keep track of all the different versions of their code. That way, if they make a mistake or want to go back to an older version, they can easily find it.

It's like a magic box that keeps everything safe and organized, so they can focus on making their code even better.

Download⬇️ | Docs📄

GitHub

GitHub is a code hosting platform for collaboration and version control. GitHub lets you work together on projects with others.

So, remember how we talked about Git being like a big box of toys for programmers? Well, GitHub is like a giant playground where all the programmers can share their toys with each other!

It's a place on the internet where programmers can put their code and other people can see it and even help make it better. It's like a big library where everyone can share their books and read other people's books too.

GitHub makes it easier for programmers to work together and make cool things like video games, websites, and apps collaboratively!

GitHub | Docs📄

Git commands

Here comes the part you have been waiting for The 5 commands with you can instantly start using git and GitHub. Yes, we can use GitHub Desktop to perform all these tasks but why settle for less when there is a better and faster way⚡.

git init

This command is used to initialize an empty git repository.

git init

git status

This command is used to check the commits and changes in the file or folder.

Remember the toy box analogy? So, Git status is a command that tells you what toys are in your box right now, and which ones have changed since the last time you checked. It also tells you if there are any new toys that you haven’t added to your box yet, or if there are any old toys that you don’t want anymore.

git status

git add

the command is used to add the changes to the commit stage.

We can add all the changes with this single command with a dot at the end.

git add .

Or if we want to add only specific changes we can specify the file/folder name

git add filename

Let's get back to the toy analogy for a better understanding. Git add is a command that tells Git which toys you want to save in the special place. You can choose one toy, many toys, or even parts of a toy. When you use git add, you put your toys on a shelf that is ready for saving. But they are not saved yet! You need to use another command which we will see next to actually save them.

git commit

The command is used to save all the changes made. Here, you should also mention the commit message. It is a simple message describing what the commit is about. The same way you name a file before saving it. It makes things easier and organized.

Git commit is a command that tells Git to save your toys in the magic book (GitHub). When you use git commit, you take a picture of your toys on the shelf and note what you did with them. Then you put the picture and the note in the magic book. The magic book keeps track of all your pictures and notes so you can see them anytime.

You can write the commit message in 2 different ways

  • Using a command which included the commit message also. Preferred method.
git commmit -m"the message goes here.."

Simply do git commit and then git asks for the message separately.

git commit

git push

It helps you to save the commits that you made to the remote repository, that is from your local to the remote repository(GitHub repository).

To push the changes to your remote repository use this command

git push origin main

Here,

main is the branch to which you want to save your changes.

Origin refers to the remote repository. After pushing the commits appear in your remote repository and If you have forked the repo, then GitHub asks if you want to make Pull Request.

These are the 4 git commands with which you can immediately start using git and GitHub for your personal use or contributing to Open Source software. Yes, there are several other commands but as you know the commands which are required to start, stop procrastinating and start working now.


That's the end folks. If you have enjoyed the read and learned something and please like the blog and follow me on hashnode for more exciting blogs.