Introduction to Git!

Introduction to Git!

By Zuber Dunge

Here's what we'll go over in this article:

So, What is Git?

What is Git?

Well, In Technical Terms Git is an Open Source Distributed Version Control System. yeah I know it might go above your head but don't worry I'll explain it in simple terms.

In the lamest term,

Git is like a History sheet but an advanced one! Where you can check the history of changes done in the file/code. Git shows you what changes have been made and When it was made and by who.

And it just doesn't show you the history but also allows you to Undo/Redo the changes. It is kinda Time Stone LMAO!


Why to use Git?

Why to use Git?

Git has been designed with performance, security, and flexibility in mind.

Performance

  1. Git's performance is very strong and reliable as compared to other git alternatives.
  2. Being distributed enables significant performance benefits as well.
  3. One of Git's performance strengths is its advanced algorithms.

Flexibility

  1. Git tracks the changes while someone makes changes in a file with a commit message.
  2. Git helps to maintain the source code backup and can restore it.
  3. Git deploys the source code on the server with only one command.

Security

  1. Top priority of Git is the integrity of managed source code.
  2. Git repositories are secured with a cryptography hashing algorithm called SHA1.
  3. It protects the code and the change history against both accidental and malicious change and ensures that the history is fully traceable.

Also,

  • Over 70% of developers use Git!
  • Developers can work together from anywhere in the world.
  • Developers can see the full history of the project.
  • Developers can revert to earlier versions of a project.

Who Created Git?

Linus Torvalds

Linus Torvalds

p.s. Linus Torvalds is the same person who created LINUX!

According to the official Git Website, As with many great things in life, Git began with a bit of creative destruction and fiery controversy.

The Linux kernel is an open-source software project of a fairly large scope. For most of the lifetime of the Linux kernel maintenance (1991–2002), changes to the software were passed around as patches and archived files. In 2002, the Linux kernel project began using a proprietary DVCS called BitKeeper.

In 2005, the relationship between the community that developed the Linux kernel and the commercial company that developed BitKeeper broke down, and the tool’s free-of-charge status was revoked. This prompted the Linux development community (and in particular Linus Torvalds, the creator of Linux) to develop their own tool based on some of the lessons they learned while using BitKeeper. Some of the goals of the new system were as follows:

  • Speed
  • Simple design
  • Strong support for non-linear development (thousands of parallel branches)
  • Fully distributed
  • Able to handle large projects like the Linux kernel efficiently (speed and data size)

Since its birth in 2005, Git has evolved and matured to be easy to use and yet retain these initial qualities. It’s amazingly fast, it’s very efficient with large projects, and it has an incredible branching system for non-linear development.


Installation

How to install Git on any OS

Installation

Git can be installed on the most common operating systems like Windows, Mac, and Linux. In fact, Git comes installed by default on most Mac and Linux machines!


Git for Windows

  1. Download the latest Git for Windows installer.

  2. When you've successfully started the installer, you should see the Git Setup wizard screen. Follow the Next and Finish prompts to complete the installation. The default options are pretty sensible for most users.

  3. Open a Command Prompt.

  4. Run the following commands to configure your Git username and email using the following commands. These details will be associated with any commits that you create:

    $ git config --global user.name "Your Name"
    
    $ git config --global user.email "Sample@gmail.com"
    

Git for Mac

Most versions of macOS already have Git installed, you just have to activate it through the terminal with the git version. However, if you don't have Git installed for whatever reason, you can install the latest version of Git using the below steps:

1.Download the latest Git for Mac installer.

2.Follow the prompts to install Git.

3.Open a terminal and verify the installation was successful by typing git --version:

$ git --version

4.Configure your Git username and email using the following commands. These details will be associated with any commits that you create:

$ git config --global user.name "Your Name"
$ git config --global user.email "Sample@gmail.com"

Git for LINUX

As I just said that Git was developed by the same person who created LINUX. and 2nd thing about Git is that It was originally developed to version the Linux operating system! So, Now it makes sense that why it is easy to configure to run on Linux.

Debian/Ubuntu

1.From your shell, install Git using apt-get:

$ sudo apt-get update
$ sudo apt-get install git

2.Verify the installation was successful by typing git --version:

$ git --version

3.Configure your Git username and email using the following commands. These details will be associated with any commits that you create:

$ git config --global user.name "Your Name"
$ git config --global user.email "Sample@gmail.com"

Fedora

1.From your shell, install Git using dnf (or yum, on older versions of Fedora):

$ sudo dnf install git

2.Verify the installation was successful by typing git --version:

$ git --version

3.Configure your Git username and email using the following commands. These details will be associated with any commits that you create:

$ git config --global user.name "Your Name"
$ git config --global user.email "Sample@gmail.com"

We've successfully installed Git now let's move to the next section!


Basic Commands of Git

Basic Commands of Git

From scratch -- Create a new local repository

$ git init [project name]

Download from an existing repository

$ git clone my_url

List new or modified files not yet committed

$ git status

Show full change history

$ git log

List all local branches

$ git branch

List all branches, local and remote

$ git branch -av

Switch to a branch, my_branch, and update the working directory

$ git checkout my_branch

Create a new branch called new_branch

$ git branch new_branch

Delete the branch called my_branch

$ git branch -d my_branch

Merge branch_a into branch_b

$ git checkout branch_b
$ git merge branch_a

Stages the file, ready for commit

$ git add [file]

Stage all changed files, ready for commit

$ git add .

Commit all staged files to versioned history

$ git commit -m “commit message”

Commit all your tracked files to versioned history

$ git commit -am “commit message”

Unstages file, keeping the file changes

$ git reset [file]

Revert everything to the last commit

$ git reset --hard

Get the latest changes from the origin (no merge)

$ git fetch

Fetch the latest changes from the origin and merge

$ git pull

Fetch the latest changes from the origin and rebase

$ git pull --rebase

Push local changes to the origin

$ git push

When in doubt, use git help

$ git command --help

Some of the Popular Git Management Services

Git suggests some repository management services that you can find useful. In general, repository management services are the key to fast and effective software development. The most popular ones based on Git are GitHub, Bitbucket, and GitLab.

GitHub

GitHub is a git-based repository host originally launched in 2008 by Tom Preston-Werner, Chris Wanstrath, and PJ Hyatt. It is the largest repository hosting platform with more than 38 million projects. It permits to host and review code, manage projects and build software.

Bitbucket

Bitbucket was launched in 2008 by an Australian startup and originally supported only Mercurial projects. In 2010 Bitbucket was bought by Atlassian, and from 2011, it started to support Git hosting, which is now its main focus. It provides free unlimited private repos, Jira and Trello integration, and built-in continuous delivery.

GitLab

GitLab started as a project by Dmitriy Zaporozhets and Valery Sizov in 2011, which aim was to provide an alternative to the available repository management solutions. The company was, however, only incorporated in 2014. It provides continuous integration and delivery, agile development, Auto DevOps, etc.


Conclusion

I hope you folks now have a basic idea of What's Git, Who Created It, How to Install it on your machine, How does it work, Some basic Git commands. (you should try those commands instead of just reading them, you'll understand better!) We also checked out some of Git Management Services like GitHub, Gitlabs, etc.

When you're working with git make sure you use the right Git Service. I personally use GitHub (well I've tried GitHub only so).

Which one do you prefer/use? Tell us in the comment section :)

LOL! (Lots of Love)

Thank You!

Also, Don't forget to share <3

Did you find this article valuable?

Support Zuber Dunge by becoming a sponsor. Any amount is appreciated!