Beginner's guide to Git and GitHub

Introduction and History

In general words, Git is a distributed version control system that is widely used for tracking changes in source code during software development. It was created by Linus Torvalds in 2005 and has since become one of the most popular VCS tools in the software development industry.

Let’s imagine a situation to understand how Git works and how it can solve real-world problems. Imagine you’re a developer, and a client named Harry asks you to create a messaging app. You build the app, which is initially 500 MB in size. You zip it and send it to Harry. Later, Harry asks you to add a video calling feature to the app. After adding this feature, the app’s size increases to 550 MB (500 MB from before and an additional 50 MB for video calling). You zip this new version and send it to Harry. This process repeats every time Harry wants to add a new feature, requiring you to zip a new version and send it to him. This method takes a lot of storage in both client’s and developer side and is inefficient for keeping track of app versions and becomes quite troublesome.

Similarly, Linus Torvalds, known for creating the Linux Kernel, faced a similar problem when he developed Linux as an open-source project, allowing many developers to contribute. Initially, developers sent him zip files containing updates and new versions of Linux. Storing and managing all these files became extremely challenging for Linus. To address this issue, he created a version control system called Git, which allows you to keep track of projects by taking snapshots, making collaboration and project management much more efficient.

Some of the key concepts and features of Git are:

  1. Version Control: Git allows developers to keep track of changes made to their code over time.

  2. Distributed: Git is a distributed VCS, which means that each developer working on a project has a complete copy of the entire repository, including the entire history of changes.

  3. Repository: In Git, a repository (often pronounced as “repo” is a data structure that stores a collection of files and their history of changes. It is the fundamental unit used for version control in Git, allowing multiple users to collaborate on a project.

  4. Branching: Git makes it easy to create branches, which allows multiple developers to work on different features or bug fixes concurrently without interfering with each other.

  5. Merging: Git provides tools for merging changes from one branch to another which is very handy while doing large projects.

  6. Commit: A commit in Git represents a snapshot of the code at a particular point of time. Developers create commits to record changes and provide meaningful commit changes to describe what was done. Don’t worry, you will be able to see the practical demo later on.

  7. Remote Repositories: Git allows you to work with remote repositories hosted on servers like GitHub, Gitlab etc.

  8. Open Source: Git is open-source software, its source code is freely available to anyone.

  9. Command- Line Interface (CLI): Git can be used via the command line, which is the most powerful and flexible way to interact with it.

  10. GitHub and GitLab: These are popular web-based platforms that use Git for version control and offer additional features like issue tracking and project management. They also provide a graphical interface on top of Git. Think of Git like the main tool or software, and GitHub and GitLab as special tools built on top of Git.

Hands-on Demo:

First of all create a directory on your computer and open terminal at the folder

  1. To set up Git in your directory, use the “git init” command. This command initializes Git in the directory and begins monitoring all the changes made in that directory.

Suppose, I make a txt file name and write some text message in it…….

2. When you execute the “git status” command, it provides information about any untracked files and advises us to commit them to ensure they are properly tracked.

3. Execute “git add .” to stage all the changes in your working directory for the next commit in a Git repository.

  • Staging Changes: When you work on a project, you make changes to files in your working directory. These changes are not automatically included in the next commit. You need to tell Git which changes you want to include in the commit by staging them.

4. Execute “git commit -m “message” ” to create a new commit with a specific commit messages.

5. By executing “git log” command you can view the commit history of the git history.

6. To go to a specific commit/version in Git, you can use the “git checkout” command followed by the commit’s identifier (usually a commit hash or a branch/tag name).

  • You can get the commit hash using git log command……..