Day 8 Task: Basic Git & GitHub for DevOps Engineers.

Day 8 Task: Basic Git & GitHub for DevOps Engineers.

"Empowering Collaboration and Version Control for Developers"

ยท

8 min read

๐Ÿ”ถ What is Git?

Git is a version control system that allows you to track changes to files and coordinate work on those files among multiple people. It is commonly used for software development, but it can be used to track changes to any set of files.

With Git, you can keep a record of who made changes to what part of a file, and you can revert to earlier versions of the file if needed. Git also 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 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 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.

๐Ÿ”ถ What is Version Control? How many types of version controls do we have?

Version control is a system that tracks changes to a file or set of files over time so that you can recall specific versions later. It allows you to revert files to a previous state, revert the entire project to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.

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

  1. A centralized version control system (CVCS) uses a central server to store all the versions of a project's files. Developers "check out" files from the central server, make changes, and then "check-in" the updated files. Examples of CVCS include Subversion and Perforce.

  2. A distributed version control system (DVCS) allows developers to "clone" an entire repository, including the entire version history of the project. This means that they have a complete local copy of the repository, including all branches and past versions. Developers can work independently and then later merge their changes back into the main repository. Examples of DVCS include Git, Mercurial, and Darcs.

๐Ÿ”ถ 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.

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

๐Ÿ”ถ Task 1: Install Git on your computer (if it is not already installed). You can download it from the official website at https://git-scm.com/downloads

To install it with the Ubuntu

#To install it with the Ubuntu
sudo apt update
sudo apt install git
#To confirm that you have installed Git
git --version

๐Ÿ”ถ Task 2: Create a free account on GitHub (if you don't already have one). You can sign up at https://github.com/

๐Ÿ”ถ Task 3: Learn the basics of Git by reading through the video This will give you an understanding of what Git is, how it works, and how to use it to track changes to files.

Understanding the basics of Git is essential for any developer looking to participate in collaborative software development. Here are the fundamentals of Git:

  1. Repository (Repo): A repository is a central database where all versions of a project's code are stored. It contains the complete history of changes, known as commits. Git can handle multiple repositories, including local repositories on your development machine and remote repositories on servers like GitHub, GitLab, or Bitbucket.

  2. Commit: A commit represents a snapshot of the changes made to the project at a specific point in time. Each commit has a unique identifier (SHA-1 hash), author's name, email, timestamp, and a commit message describing the changes made. Commits allow developers to track the history of the project and revert to previous versions if needed.

  3. Branch: A branch is a separate line of development that allows developers to work on different features or bug fixes independently. The main branch is typically called "master" or "main," and new branches are created from it. Developers can merge branches back into the main branch when the work is complete.

  4. Clone: Cloning is the process of creating a copy of a remote repository on your local machine. It allows you to work on the project locally and push changes back to the remote repository when ready.

  5. Pull: Pull is used to update your local repository with the latest changes from a remote repository. It combines the "fetch" (download changes) and "merge" (apply changes) operations into one command.

  6. Push: Push is used to upload your local commits to a remote repository. It updates the remote repository with the changes you've made locally.

  7. Fetch: Fetch is used to download changes from a remote repository without automatically merging them into your local branch. It allows you to review changes before merging them.

  8. Merge: Merge combines changes from one branch into another. It is used to integrate changes from a feature branch back into the main branch.

  9. Pull Request (PR): In collaborative development, a pull request is a request to merge changes from a branch into the main branch. It allows team members to review the changes before merging.

  10. Remote: A remote is a reference to a repository located on a server, such as GitHub or GitLab. It allows developers to collaborate with others by pushing and pulling changes to and from the remote repository.

These are the core concepts of Git that every developer should understand. Learning Git enables efficient collaboration, version control, and effective project management, making it an indispensable tool for modern software development workflows.

๐Ÿ”ถ Exercises 1: Create a new repository on GitHub and clone it to your local machine

Creating a new repository (repo) on GitHub is a straightforward process. Here are the steps to create a new repository:

  1. Log in to GitHub: If you don't have a GitHub account, sign up for one at https://github.com/join. If you already have an account, log in using your credentials.

  2. Go to Your GitHub Dashboard: After logging in, you will land on your GitHub dashboard.

  3. Create a New Repository: In the top-right corner of the GitHub dashboard, click on the "+" icon, and then select "New repository" from the dropdown menu.

    New Repository

  4. Fill in the Repository Details: On the "Create a new repository" page, you will need to provide the following details:

    • Repository name: Choose a name for your repository. It should be descriptive and relevant to your project.

    • Description: Optionally, add a short description of your repository.

    • Visibility: Choose whether the repository will be public (visible to everyone) or private (accessible only to collaborators you invite).

    • Initialize this repository with You can choose to initialize the repository with a README file, a .gitignore file, or a license. These files are essential for most projects.

    • Add .gitignore: Select the programming language or framework you are using, and GitHub will generate a .gitignore file that excludes unnecessary files from version control.

    • Choose a license: Select an open-source license for your project. It's a good practice to choose a license that suits your project's requirements.

      Create Repository

  5. Create the Repository: Once you've filled in the details, click the "Create Repository" button. Your new repository will be created, and you'll be redirected to its page.

  6. Set Up the Repository: On your repository page, you'll find the repository's URL, which we have to clone the repository to your local machine using Git. we can also customize the repository's settings, add collaborators, and manage various aspects of the repository from this page.

  7. Clone the Repository: To start working on your project locally, we have to clone the repository to our local machine using the git clone command. The repository URL is available on the repository page.

๐Ÿ”ถ Exercises 2: Make some changes to a file in the repository and commit them to the repository using Git

๐Ÿ”ถ Exercises 3: Push the changes back to the repository on GitHub

git push -u origin main

In conclusion, GitHub is a powerful platform that revolutionizes the way developers collaborate, manage, and share their code. It serves as a centralized hub for version control, allowing teams to work together seamlessly on projects of any size.

Stay in the loop with my latest insights and articles on cloud โ˜๏ธ and DevOps โ™พ๏ธ by following me on Hashnode, LinkedIn (https://www.linkedin.com/in/chandreshpatle28/), and GitHub (https://github.com/Chandreshpatle28).

Thank you for reading! Your support means the world to me. Let's keep learning, growing, and making a positive impact in the tech world together.

Linux Devops #Devopscommunity #90daysofdevopschallenge

Did you find this article valuable?

Support Chandresh Patle's Blog by becoming a sponsor. Any amount is appreciated!

ย