Day 8 Basic Git & GitHub for DevOps Engineers

Day 8 Basic Git & GitHub for DevOps Engineers

Basic Git & GitHub for DevOps Engineers

Q What is Git?

Git is a distributed version control system that allows developers to manage and track changes to source code and other files. It was created by Linus Torvalds in 2005 to manage the development of the Linux kernel.

Git allows multiple developers to work on the same codebase simultaneously, making it easier to collaborate on software projects. It tracks changes to the codebase over time, allowing developers to revert to earlier versions of the code or merge changes made by different developers.

Git uses a decentralized model, meaning that each developer has their own copy of the codebase on their local machine, as well as a complete copy of the entire project history. This allows developers to work offline and merge changes with other developers when they have an internet connection.

Git also includes features such as branching and tagging, which allow developers to create separate "branches" of the codebase for experimenting with new features or making bug fixes without affecting the main codebase. This can help reduce the risk of introducing bugs or breaking the codebase when making changes.

Overall, Git is a powerful tool for software developers that helps to streamline collaboration and manage changes to codebases over time.

Q What is Github?

GitHub is a web-based platform that provides hosting for Git repositories. It allows developers to store, share, and collaborate on their code with other developers around the world.

GitHub provides a user-friendly interface for working with Git repositories, making it easier for developers to manage and track changes to their code. It also includes features such as pull requests, issues, and code reviews, which allow developers to collaborate on code changes and communicate with each other about issues or bugs.

GitHub also includes features for managing software projects, such as project boards, wikis, and milestones. These features help to organize work and track progress towards project goals.

GitHub is used by millions of developers around the world, and has become a central hub for open-source software development. Many companies also use GitHub for their internal software development, as it provides a secure and reliable platform for collaborating on code with their teams.

In summary, GitHub is a powerful tool for software development that provides a platform for managing and collaborating on Git repositories, as well as features for managing software projects and communicating with other developers.

Q What is Version Control? How many types of version controls we have?

Version control is a system that tracks changes to files over time, allowing developers to manage and collaborate on software projects more effectively. It allows developers to track changes made to a codebase, including who made the changes and when, and revert to earlier versions of the codebase if necessary.

There are two main types of version control systems: centralized version control systems (CVCS) and distributed version control systems (DVCS).

Centralized version control systems, such as CVS and Subversion (SVN), have a central repository where all files are stored and managed. Developers can check out a copy of the codebase from the central repository, make changes locally, and then commit their changes back to the central repository.

Distributed version control systems, such as Git and Mercurial, allow each developer to have their own copy of the codebase, including the entire history of changes. This allows developers to work independently and offline, and then merge their changes with other developers when they have an internet connection.

Both types of version control systems have their own advantages and disadvantages, and the choice between them often depends on the needs and preferences of the development team. However, in recent years, DVCS such as Git have become more popular due to their flexibility and ability to support distributed workflows.

Q Why we use distributed version control over centralized version control?

There are several reasons why distributed version control systems, such as Git, have become more popular than centralized version control systems, such as SVN:

  1. Offline Work: With a DVCS like Git, each developer has their own copy of the entire codebase, including its entire history. This means that developers can work offline and continue to make changes to their code, without needing to be connected to a central server. This is especially useful for developers who work in areas with poor or unreliable internet connections.

  2. Flexibility: With a DVCS like Git, developers can create branches and make changes to the codebase without affecting the main codebase. This allows developers to experiment with new features, make bug fixes, and work on their own code without affecting other developers. It also allows for more flexible workflows, such as feature branches or release branches, which can help reduce the risk of introducing bugs into the codebase.

  3. Collaboration: With a DVCS like Git, developers can easily collaborate with each other by sharing their changes via pull requests. This allows developers to review each other's code, provide feedback, and make changes collaboratively. It also allows for more efficient code reviews, as reviewers can see the changes made by the developer in their own branch, rather than having to review changes made in a centralized repository.

  4. Security: With a DVCS like Git, each developer has their own copy of the codebase, which helps to distribute the risk of data loss or corruption. In contrast, with a CVCS like SVN, if the central repository becomes corrupted or lost, all developers may lose access to the entire codebase. Additionally, because each developer has their own copy of the codebase, it can be easier to manage permissions and access control, which helps to improve security.

Overall, DVCS like Git offer several advantages over centralized version control systems, which have helped to make them more popular among software developers. However, the choice between the two depends on the needs and preferences of the development team.

Install Git on the computer

The steps to install Git on Ubuntu.

  • Open the terminal on your Ubuntu system.

  • Update your package manager's cache by running the following command:

sudo apt-get update
  • Once the update is complete, install Git using the following command:
sudo apt-get install git-all
  • Once the installation is complete, verify that Git has been installed by running the following command:
git --version
  • This should display the version of Git that has been installed on your system.

Create a free account on GitHub

Steps to create a free account on GitHub:

  1. Open your web browser and go to the GitHub website: https://github.com/

  2. Click the "Sign up" button in the top right corner of the page.

  3. On the next page, enter your username, email address, and strong password. You can also sign up using your existing Google or Microsoft account.

  4. Choose the plan you want to use. For most users, the free plan should be sufficient. Click the "Continue" button.

  5. Complete the survey by selecting the options that best describe your use of GitHub. Click the "Submit" button.

  6. Verify your email address by following the instructions sent to your email. This step is necessary to activate your GitHub account.

  7. Once your account is activated, you can start using GitHub to manage your projects, collaborate with others, and contribute to open source software.

Create a new repository on GitHub and clone it to local machine, Make some changes to a file in the repository and commit them to the repository using Git, Push the changes back to the repository on GitHub

steps to create a new repository on GitHub and clone it to your local machine:

  • Log in to your GitHub account.

  • Click on the "+" icon in the top right corner of the page and select "New repository".

  • Choose a name for your repository, and optionally add a description and a README file. You can also choose to make your repository public or private.

  • Click on the "Create repository" button to create your new repository.

  • Once your repository is created, you can clone it to your local machine by opening a terminal or command prompt and entering the following command:

git clone https://github.com/saurabhshivde?tab=repositories
  • Replace "your-username" and "your-repository" with the appropriate values for your repository. This command will download a copy of your repository to your local machine.

  • You can now start working on your project locally, making changes and committing them to your local repository. When you are ready to push your changes back to the remote repository on GitHub, you can use the following commands:

git add . 
git commit -m "commit message" 
git push
  • Replace "commit message" with a brief description of your changes. These commands will stage your changes, commit them to your local repository, and push them to the remote repository on GitHub.