Git basics: What is Git? 🤔

Git basics: What is Git? 🤔

·

5 min read

Statement: Git is the most powerful tool in modern development.

It doesn't matter in what language you develop. If you work on any development, you need Git!

Let's have a look at what Git even is and why it's so important.

This is a series around Git, Git commands, GitHub, and more ❤️


What is Git?

Git is a free open source VCS (Version Control System), which means it's a way to keep track of every change in your software.

There are more VCS in existence like CVS, SVN, and more. However, Git is by far the most used one.

You can even use Git locally on your computer to keep track of changes you make throughout the code. This is a great way to maintain a good overview of certain things that break over time.


Why do I need Git?

But far more important is that it can be distributed, meaning you can host your Git repository on an external system like GitHub, GitLab, etc.

When you do this, you can give other developers, colleagues, teammates the option to develop asynchronous with you and see the changes you have made.

This makes Git a perfect system for developers to collaborate and work together on one codebase.

Within this series, we'll also look at branching, merging, and all those fancy terms which make Git even more powerful!


A Git use case

To conclude the important, let's take a look at how things were before Git.

Abhishek would have some large project he is maintaining. Then Akash also wanted to work on the system.

Abhishek would have to put his system on an FTP, USB or transfer it via a link.

Akash would then start working, but during this time, both Abhishek and Akash might have changed the same file, but in a slightly different way.

By the time they are both done, the files will be shared back again, but which file is the right one now? There should be some combination, right!

Well, that's a massive problem.

With Git, this would have been prevented as Akash would have been able to get the codebase from a distributed Git provider, and Git would have kept track of all changes.

When both would need to merge the code, Git would tell them which lines are conflicting.

A lifesaver, thank you, Git!


How to install Git?

Git is super easy to install on any system. I've written down how to install Git for the following platforms:

  • OSX: brew install git
  • Windows: Download the installer
  • Linux (apt): sudo apt-get install git
  • Linux (yum): sudo yum install git

Once you follow these steps, run the following command to check if Git is installed correctly:

git --version

It should return a specific Git version like: git version 2.33.0.


Git Commands

In order to use the Git system, we need to learn what the commands do. So, I have compiled the commands most used by today's developers under 3 headings.

1. The following git commands must be used to submit your projects or documents to web storage services.

  • git config: Used to set configs after Git installation.

  • git init: It is used to create a local repository on the computer.

  • git add: It is used to add the selected documents to the local repository.

  • git commit: It is used to add the documents to be added to the local repository with comments.

  • git remote: It is used to determine the remote server address to which we will upload our documents.

  • git push: It is used to send the files in the local repository to the repository on the remote server.

2. Branching and merging operations are generally used when more than one person works in the projects. To perform these operations, different git commands must be used. We have compiled these for you

  • git branch: It is used to create branches.

  • git checkout: Used to switch to any previously created Branch.

  • git merge: It is used to merge the branches created.

  • git rebase: It works similarly to the "git merge" command. But it leaves no record of branching behind.

3. If we want to copy a project from the remote repository to our computer and undo the transaction after committing the documents, the following Git commands should be used.

  • git clone: It is used to copy the documents on the remote server to your computer.

  • git revert: Used to undo any committed changes.

  • git reset: It is similar to the “git revert” command, but when you run this code, the last commit you sent is deleted.

Best Git Repositories

  • GitHub is the largest and most popular code hosting service since 2008. It helps developers to store and manage their code and monitor and control changes in their code. GitHub's interface is user-friendly and easy for beginners. Using Git without GitHub usually requires more technical knowledge and more command line usage.

  • GitLab is very similar in principle to GitHub. For this reason, the best way to understand GitLab is to describe the difference between GitHub and GitLab. Compared to GitHub, GitLab includes options such as code continuity, unlimited code repository, and unlimited disk space. GitLab allows you to keep your codes on remote servers as private or public for free through Git. In short, we can say that GitLab is the open-source sharing interface version of GitHub.

Since we defined GitLab by comparing it with GitHub, then it would not be wrong to define Bitbucket with its features that distinguish it from GitLab. GitLab only supports Git repositories, while Bitbucket offers support for both Git and Mercurial. If you're using Mercurial or other repositories, switching to GitLab can be a bit complicated. Fortunately, GitLab is equipped with a repository import feature that helps users easily migrate from other platforms. Bitbucket also supports SVN, Google Code, CodePlex, HG and SourceForge as well as repository importing from Git.


Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to connect on Instagram @abhishekpatil7770

Â