DEV Community

Motabar Javaid
Motabar Javaid

Posted on

Getting Started with Git and Github

Diving into the realm of version control.

Header Image Getting Started with Git and Github

If you code or have a little bit of knowledge about it, I’m sure you’ve at least once heard of the term git. And I know, I know, It must’ve been jargon for you the first time. You’re not alone. It is indeed, for all of us.

Okay, So I know how confusing it was for me at first to even understand why would someone need git and Github and what’s a branch or push or pull bla bla bla. It was just too confusing and overwhelming to just use it even on a simpler personal project.

Until one day when I saw its capabilities. The use case, commands everything started to make sense. So today, ladies and gentlemen, I’ll try to help you’ll understand what Git is, why we use it, and how it can potentially be a lifesaver for a programmer!

Let’s start with the very basic,

Understanding Git

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

That’s the definition you’ll get if you google right now. But you won’t be here if you did understand it from google. So let’s understand it in simpler terms. Git basically is software that keeps track of your projects. So for instance, you have a project, in this case, a mobile app, that is divided into phases: Phase One is allocated to designing the UI. Phase Two is the functionality and phase three is integrating third-party services. Once you get done with Phase One, you being the clumsy coder, don’t want to make unintentional changes to the UI for the remaining of the app so you do what’s called a snapshot in git terms where you kind of make a safe save of your code for even if cases where you mess things up, you can always retrieve and come back to the point of time of the snapshot. And remember we talked about different phases? We divide the code into what’s called a branch. Where each branch is a new feature or a phase in our case. After each phase is done, we can integrate the done phases/parts into one by merging them together into what’s known as the master branch in git.

Git in group projects

Git and branches

So, git for a personal project where you’re the only one coding might not sound so convincing but when there are multiple people working on the same project, Git just makes the convenience goes into super Saiyan mode. So if you look at the photo above, there is a branch, a Master branch (the main one) and there are two more branches coming out of the main branch at one point and then merging all into the main branch at another point. That’s representing in what’s in our case would be the different phases of our mobile application where we were working on the UI Section while a colleague was working on the functionality and them we both merge them together into the main/master branch. So when you want to get a copy of the updated project, you retrieve it from the main branch with the action known as pull in git.

  • The main and master branch refer to the same thing. Its just that the master branch is now called main in Github which we’ll learn later on.

Getting started with git commands

Now that we’ve a sufficient knowledge of what git is and how it works. Let’s get into the fun part and learn how to work with it. So let’s dive in,

  • git init — Initializes an empty git repository in the current directory.

  • git status — Shows state of the working git directory.

  • git branch — Shows the branch you’re currently on

  • git add — Add something into the staging area

  • git commit — Captures a snapshot of the currently staged changes

  • git checkout — Navigate between the branches

  • git push — push local repository to a remote one (From Local to Github)

  • git pull — Fetch the remote repository and update the local one (From Github to Local)

Now that we’ve gone through the basic git commands, let’s get ourselves familiar with Github.

What is Github?

People often confuse git with Github which is understandable if you don’t know what Github actually is. So starting off with,

Github is nothing but a hosting space for our coding projects.

But that’s not all that Github has to offer. Github is a platform for code hosting along with features including version control and collaboration. Github makes it easy for us to use git by providing users with a Graphical User Interface (GUI) as opposed to git which is limited to the Command Line Interface or the CLI which makes it easier to manage our projects and collaboration in large teams.

Even though Github is not the only space that is used as an extension to git to host our code, there are several others, to name a few:

  • GitLab.

  • GitBucket.

  • SourceForge.

  • BitBucket.

But Github is the most renowned and most used platform used for hosting code.

Fun Fact: Github was acquired by Microsoft in 2018 for $7.5B

So, Github works exactly the same way as git does, the major difference being the Master branch is called the main branch in github which doesn’t make a difference in most cases except when you intend to push your code to the ‘main branch’ of Github and you mistakenly create a new branch called main cause you’re too used to git :p

With that, I think we’re pretty much done for this article. Thanks for reading this article! ❤️ You can find all the code on my github @WhatsApp Clone Repo

That's all folks

That’s all for now Folks Thanks for reading this article ❤️ I hope you learned something new today.
Clap 👏 If this article helped you.

Feel free to post any queries or corrections you think are required ✔

Do leave a feedback so I can improve on my content. Thankyou! 😃

If you’re interested, here are some of my other articles:

Top comments (0)