๐Ÿš€ Day 8:Basic Git & GitHub for Dev0ps Engineers.

๐Ÿš€ Day 8:Basic Git & GitHub for Dev0ps Engineers.

ยท

5 min read

*Version control is an essential aspect of software development and collaborative projects. Git and GitHub are two powerful tools that make version control and collaboration easier. In this article, we'll explore the basics of Git, understand what GitHub is, and outline the key differences between centralized and distributed version control systems.

What is Git?

Git was created by Linus Torvalds in 2005 to develop Linux Kernel. Git is an open-source distributed version control system. It is designed to handle minor to major projects with high speed and efficiency. It is developed to coordinate the work among the developers. The version control allows us to track and work together with our team members in the same workspace.

What is GitHub?

GitHub is a web-based platform that provides hosting for version control using Git. It serves as a central hub for software development, offering a wide range of features and tools to support collaborative coding, project management, and open-source contributions. GitHub is widely used by individual developers, teams, and organizations to manage and share their software projects.

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

GitHub is a web-based platform that provides hosting for version control using Git. It is a subsidiary of Microsoft, and it offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its own features. GitHub is a very popular platform for developers to share and collaborate on projects, and it is also used for hosting open-source projects.

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

  1. Centralized Version Control System (CVCS):

    is a type of version control system used to manage and track changes to files and projects. In a CVCS, there is a central server or repository that stores all versions of a project's files and acts as the authoritative source of truth for the codebase. Developers check out files from this central repository, make changes, and then check them back in, allowing the central server to maintain a history of all changes.

  2. distributed version control system (DVCS):

    (DVCS) is a type of version control system that allows multiple developers to work on a project concurrently and independently. Unlike (CVCS), where there is a single central repository, in a DVCS, each developer has a complete copy of the entire project repository, including the full history of changes.

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

  1. Better collaboration: In a DVCS, every developer has a full copy of the repository, including the entire history of all changes. This makes it easier for developers to work together, as they don't have to constantly communicate with a central server to commit their changes or to see the changes made by others.

  2. Improved speed: Because developers have a local copy of the repository, they can commit their changes and perform other version control actions faster, as they don't have to communicate with a central server.

  3. Greater flexibility: With a DVCS, developers can work offline and commit their changes later when they do have an internet connection. They can also choose to share their changes with only a subset of the team, rather than pushing all of their changes to a central server.

  4. Enhanced security: In a DVCS, the repository history is stored on multiple servers and computers, which makes it more resistant to data loss. If the central server in a CVCS goes down or the repository becomes corrupted, it can be difficult to recover the lost data.

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

Step 1: Create a New Repository on GitHub:

  1. Log in to your GitHub account

  2. GitHub homepage and select "New repository."

  3. Fill out the repository information:

  4. Click the "Create repository" button.

    Step 2: Clone the Repository to Your Local Machine:

command:git clone https://github.com/<user>/<repositiry name>

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

Step 1: Navigate to Your Local Repository:

command: cd /path/to/your/repository

Step 2: Edit the File, Save the Changes & Check the Status:

command:vim <filename.txt>

command:git status

Step 3: Stage the Changes:

command:git add <filename.txt>

Step 4: Commit the Changes:

command: git commit -m "type your commit message here"

Step 5: Push to the Remote Repository :

If your repository is connected to a remote repository on GitHub then you can push your changes to the remote repository using the git push command:

Your changes are now committed to your local Git repository. If you've pushed these changes to a remote repository on a platform like GitHub, they will be visible to collaborators there as well.

Remember to commit your changes regularly to maintain a well-documented history of your project's development.

3. Push the changes back to the repository on GitHub

Step 1: Verify Your Remote Repository:

Before pushing your changes, make sure that your local Git repository is connected to the remote repository on GitHub You can check this by using the following command:

Step 2: Push Your Changes:

Command: git push origin < brach-name>

Step 3: Authenticate on GitHub:

When you run the git push command, Git will prompt you to enter your GitHub credentials or provide a personal access token if you haven't already authenticated.

Step 4: View Your Changes on GitHub:

After a successful push, your changes will be visible in the remote repository on GitHub. You can visit your repository's GitHub page to confirm that the changes have been applied.

ย