An Introduction to Git and Github

Aritra RayAritra Ray
8 min read

Introduction:

Git is a version control system that helps developers manage and keep track of changes in their code and GitHub is a web-based platform that hosts Git repositories. It makes sharing, collaborating, and tracking your project progress easier.

Version Control:

Version control is a system is also known as source control. It is the the practice of managing changes to a codebase over certain period of time.Version control softwares keeps track of every modification of the code in the special kind of database. If mistake is made , developers can turn back the clock and compare earlier versions of code to help fix the mistake. Overall version control ensures that changes in the codebase are recoverable , and easily managed .

Then you may think that why should I use such version control ?

well the answer is , we may not require the history of the commits and all the codes while making small project on our own , but when developers works in a team they need to work simultaneously on the same codebase. It enables the developer to track or modifications , collaboration and maintaining a history of the project . Overall we can conclude that version control ensures code quality , accountability and efficient collaboration in projects.

Why should we use git ?

There are various version control system available in the internet . Then why should we use git over other VCS (version control system ):

Distributed Version Control:

Unlike centralized VCS like SVN or CVS, Git allows every developer to have a full local copy of the repository with complete history. This means that all changes can be made, tracked, and committed locally without an internet connection.

Branching and Merging:

Git makes branching and merging incredibly efficient and easy. Branches in Git are lightweight and enable developers to try out new features, bug fixes, or experiments in isolated environments.

Efficient Performance:

Git is optimized for performance, particularly for handling large projects. Git’s performance for fetching, committing, and comparing changes is fast

Open Source and Widely Supported:

Git is free and open-source, making it highly customizable and adaptable. It is also widely supported by platforms like GitHub, GitLab, and Bitbucket, offering collaborative tools for issue tracking, pull requests, and more.

Integrity and Security:

Git uses SHA-1 hashing to ensure the integrity of the repository and the history of commits

Installing Git Locally

To install Git on your local machine , you need to install it locally .The installation process varies depending on your operating system:

  • On Windows: Download the binary from the Git or Github release page and follow the installation instructions.

  • On macOS(using Homebrew) : Run brew install git in your terminal .

  • On Linux : Run sudo apt-get install git or sudo yum install git

    depending on your distribution.

Once git is installed successfully , you can verify the Git version by running git —version in your terminal . This will display the currently installed Git version .

if you can see this kind of output in your terminal , then congratulations , you have successfully installed git locally.

Terms related to git :

Before using git we should know some commonly used terms related to git .

Repository:

A repository is a storage location for project’s code , documentation and other files. It serves as a central hub for collaboration , version control, and code management.It allows multiple people to work on the project without overwriting each other’s work.

Usually a different repository is maintained for a specific project . In lemon terms Repository is also called as “repo”.

Initializing repository:

The git init command creates a new Git repository. Going inside the folder and then running the command can convert an existing project into a Git repository. This command sets up all the necessary files and folders for version control, allowing you to start tracking changes in your project.project to a Git repository or initialize a new, empty repository . Most other Git commands are not available outside of an initialized Repository:

A repository is a place where a project's code, documentation, and other files are stored. It acts as a central hub for collaboration, version control, and code management. It allows multiple people to work on the project without overwriting each other's work.

Typically, a separate repository is maintained for each specific project. In simple terms, a repository is also called a "repo."

Initializing a Repository:

The git init command creates a new Git repository. By going inside a folder and running this command, you can convert an existing project into a Git repository. This command sets up all the necessary files and folders for version control, allowing you to start tracking changes in your project. Most other Git commands are not available outside of an initialized repository., so it is the first command you’ll run in a new project.

Executing git init creates a .git subdirectory. in the current working directory , which contains all the metadata for the new repository.

Git config:

Git config commands allows us to customize and configure various aspect of your Git enhancing the development workflow .

In this section we will explore a range of Git config commands that enables you to set user details, define global and local settings and more .

The most basic use for git config is to invoke it with configuration name , which will display the set value at that name .Configuration names are dot Typically, a separate repository is maintained for each specific project. In simple terms, a repository is also called a "repo."

Initializing a Repository:

The git init command creates a new Git repository. By going inside a folder and running this command, you can convert an existing project into a Git repository. This command sets up all the necessary files and folders for version control, allowing you to start tracking changes in your project. Most other Git commands are not available outside of an initialized repository, so it is the first command you’ll run in a new project.

Executing git init creates a .git subdirectory in the current working directory, which contains all the metadata for the new repository.

Git config:

Git config commands allow us to customize and configure various aspects of Git, enhancing the development workflow.

In this section, we will explore a range of Git config commands that enable you to set user details, define global and local settings, and more.

The most basic use for git config is to invoke it with a configuration name, which will display the set value for that name. Configuration names are dot-separated. strings composed of a ‘section’ and 'key’ based on their hierarchy .

git config user.email

in this above example , email is a child property of the user configuration block . This will return the configured email address, if any , that Git will associate with locally created commits.

Git config levels and files :

Before we further discuss git config usage , let’s take a moment to cover configuration levels. The git config commands can accept argument to specify which configuration level to operate on.

  • —-local : By default , git config will write to a local level if no

    configuration option is passed. Local level configuration is applied to context repository git config gets invoked in .

  • —global: Global level configuration is user-specific , meaning it is applied to an operating system user. Global configuration values are stored in a file that is located in a user’s home directory.

    ~ /.gitconfig on unix system and C:\Users\\.gitconfig on windows .

  • —system : System-level configuration is applied across an entire machine . This covers all users on an operating system and all repos. This system level configuration file lives in a gitconfig file off the system root path .

This might get overwhelming , But don’t worry we are going to discuss it in lemon terms .

What we have learnt , let’s look at an example in which we write a value:

git config -—global user.email “your_own@example.com”

This example writes the value “your_own@example.com” to the configuration name user.email . It uses the -—gobal flag so this values is set for the current operating system user.

There are various use cases where these git config is used like as a merge tool , to change the colored outputs etc.

For further interest you can check this article .

I think , now it’s clear how git config works.

Working Directory

A working directory in Git is the local environment where files are stored and modified as part of a project. It reflects the current state of the project’s files, allowing developers to edit, add, or delete files. Changes made in the working directory can be staged for commit, which means they’re prepared for inclusion in the next commit. The working directory is connected to the Git repository, and it helps manage the differences between the committed history and the current state of the files. It plays a central role in tracking changes, testing, and developing new features.

Staging Area

Staging area serves as an intermediate step between your local repository changes and the actual commits.

  • Temporary storage : The staging area holds changes that intended to be part of the next commits.

  • Previewing changes: It allows you to preview your changes before committing them.

Committing Changes:

Committing changes in Git is a crucial part of version control. It allows you to save progress and record a snapshot of your control allowing you to save your progress and record a image of the project’s current state.

git commit command is used to do so. Prior to git commit , The git add command is used to promote or ‘stage’ changes to the project that will be stored in a commit . These two commands git commit and git add are the most frequently used.

Conclusion :

Thus we get the basic idea of git and github . We can now move further and dive deep into the git commands with much more functionality.
Thanking you.

50
Subscribe to my newsletter

Read articles from Aritra Ray directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aritra Ray
Aritra Ray