Day 8 - Basic Git & GitHub

ยท

7 min read

Introduction

In this blog, we are gonna have an overview of Git and GitHub, understand their differences and dive deep into it. Along with that we will delve into the world of version control, explore some major types of version controls and their pros and cons. To sum it up, we'll have an interactive practice session for our hands on practice by the end of this blog. So let's just jump into it.

Git & GitHub

What is git?

Git is a distributed version control system that is used for tracking changes made to a file or a set of files and allows multiple users to collaborate and work together on a file. Mostly it is used by software developers to track the changes made in their codes, collaborating with multiple developers to make software better and controlling the version.

But it can be used by anyone in any field because it is set to track changes made to a given set of file.

Benefits:

  • Track changes made in a file: This includes a record of who made changes to what part of a file.

  • Revert any change: Suppose someone made an unsuitable change, with the help of git you can revert the changes to the previous version of that file.

  • Collaboration made easy: Git makes it easy to collaborate with others, as you can share changes and merge the changes made by different people into a single version of a file.

What is GitHub?

GitHub is a web-based platform that provides hosting for distributed version control by Git. It provides all the functions of git such as distributed version control, source code management and few more features.

GitHub is simply Git on Web. Mostly it is used by developers as it made collaborating and version control easier with more user friendly features and it is also used for hosting open-source projects.

Version Control

Version control is a system that tracks changes to a file or set of files over time. Its functionality includes comparing changes over time, bug fixes and recalling specific versions later. It allows us to revert files back to their previous state, revert the entire project back to a previous state or version, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.

Suppose someone made a change to a Windows Software by Microsoft in its latest update and it started causing a problem. So the developers can revert the entire version to its previous state or previous version. This will fix the errors and later they can release new version. So this is how version control works.

Types of Version Control:

There are two main types of version control systems: centralized version control systems and distributed version control systems.

  1. Centralized version control system (CVCS): In a centralized version control system, a server works as the main centralized repository which stores every version of code. The developers can commit directly to the main branch. So this is basically useful for smaller projects.

    Read more, Here.

  2. Distributed Version Control System (DVCS): In a distributed version control system, the users have the freedom to clone the entire repository into their local machine. They can make certain changes according to their will and commit the changes to their local repository. After that in order to merge it with the man repository, the user raise request the "master" branch called "Pull-Request" to merge their changes, and then commit the changes.

    The master will then check the Pull-request and "merge" the changes to the master branch.

    NOTE: The cloned repository is disconnected from the main repository. No changes made on the cloned repo will show on the main repo unless raised a pull request and merged.

DVCS vs CVCS

Here are the major differences between Distributed version control and Centralized Version control :

Distributed Version Control (DVCS)Centralized Version Control (CVCS)
Each user has a complete copy of the repo.Users check out a working copy from the central repo.
No heavy reliance on network connectivity.Requires network connection for most operations.
Users can work offline with a local copy.Offline work is limited, as constant connection to the central repo is needed.
Each local copy serves as a complete backup.Central repo is the single point of backup.
Faster and more flexible branching and merging.Branching and merging may be slower and less flexible.
Enables parallel development with ease.Parallel development may face more challenges.
Git, Mercurial, BazaarCVS, SVN

Overall, the decentralized nature of a DVCS allows for greater collaboration, flexibility, and security, making it a popular choice for many teams.

Tasks:

Before Moving forward, here are some tasks you need to perform:

Task:

  • Install Git on your computer (if it is not already installed).

  • Create a free account on GitHub (if you don't already have one). You can sign up at https://github.com/

  • Learn the basics of Git by reading the GitHub docs. This will give you an understanding of what Git is, how it works, and how to use it to track changes to files.

Exercises:

  1. Create a new repository on GitHub and clone it to your local machine

  2. Make some changes to a file in the repository and commit them to the repository using Git

  3. Push the changes back to the repository on GitHub

Solution:

  1. Create a repository on GitHub

    Click the + sign at the top right corner to create a new repository. Repositories are like your code folders online.

    You will get a Prompt like this and you can name your repo. I have named it Practice_repo .

    Name your repository and give it a description (this is optional).

    Click the "Create repository" button to create the repository. You will be prompted to this page:

    Cloning the repo :

    Copy the HTTPS and use git clone command followed by the https address to clone the repo in your local repository.

    The Repo is cloned in your local system.

  2. Making changes in the README.md file and commit the changes.

    To make the changes we need to move to the Practice_repo directory first where the file is located.

    Use cd command.

    Now Edit the README.md file and save the changes

    Now, use the following commands to push it to your repo:

    git init : This will initialize git in your local repo.

    git add .: This will add all the files to the staging area.

    git commit -m "first commit" : This will commit the code with the message first commit.

    git branch -M main : For the branch we want to push.

    git remote add origin https://github.com/C0dewordSky/Practice_repo.git : This will connect your local machine to your repo on GitHub. In case you cloned the repo, it will already exist.

  3. git push -u origin main : Command to push to your repo

    Successfully Pushed to the GitHub repo. Now Verify

    Now you can see the changes are quickly shown on the GitHub repository.

You can use my GitHub repo to practice your GitHub skills. Here's the link. See you around.

Conclusion

In this blog we explored Git and GitHub - important tools for model manipulate and collaborative coding. Git, a dispensed device, allows for higher trade tracking and collaboration, at the same time as GitHub, its internet-based totally counterpart, optimizes the person experience. Understanding model manage is fundamental to venture fulfillment, and the distinction among centralized (CVCS) and dispensed (DVCS) structures is essential. DVCS, with examples like Git and Mercurial, offers rapid conversion and branching for offline work. GitHub makes it clean to host open-source initiatives. Git and GitHub adoption simplifies development, provides collaboration and powerful model manage. Whether you're an experienced developer or new to model manipulate, these tools are your gateway to collaborative coding success!

Ending this with a quote:

Every line of code is a step toward progress. Embrace the challenge, celebrate the small victories, and remember: your code has the power to create, innovate, and inspire change

Happy Learning.

Did you find this article valuable?

Support DevOps with Aakash by becoming a sponsor. Any amount is appreciated!

ย