Basic Git & GitHub for DevOps Engineers (day-8-task)

Basic Git & GitHub for DevOps Engineers (day-8-task)

1.What is Git?

Git 3d models

Git is a free and open-source distributed version control system designed to track changes in source code over time, allowing multiple developers to work collaboratively on the same codebase.

With Git, developers can keep track of code changes, revert to previous versions if necessary, and merge changes made by multiple developers into a single codebase. Git also supports branching, which allows developers to experiment with new features or fixes without affecting the main codebase.

Git is widely used by software development teams and is supported by hosting services like GitHub, Bitbucket, and GitLab, among others. To use Git, developers typically work with a local repository on their machine, which can be connected to a remote repository to synchronize changes with other developers. Git uses a command-line interface, through graphical user interfaces and integrated development environment (IDE) extensions are also available for those who prefer them.

2.What is Github?

What Is the GitHub Social Circle and How You Can Create One?

GitHub is a web-based platform that provides hosting for Git repositories. It is a cloud-based service that allows developers to store and manage their software projects and collaborate with others.

Developers can upload code repositories to GitHub, where it can be accessed and edited by other members of the development team or the public. GitHub provides tools for reviewing, commenting on and merging changes to code, making it easier for multiple developers to work together on a project.

GitHub is widely used in the software development industry for collaboration, version control, and software project management. It also provides features for issue tracking, project management, team communication, and code quality analysis.

GitHub also hosts a vast number of open-source repositories contributed by its user community, including libraries, frameworks, and applications that are freely available for other developers to use and contribute to.

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

Version control is the practice of tracking and managing changes to software code or other types of files over time. It allows developers to keep track of changes to code, revert to earlier versions if necessary, and collaborate with other developers on the same codebase.

Version Control Images – Browse 113,463 Stock Photos, Vectors, and Video |  Adobe Stock

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

  1. Centralized Version Control Systems (CVCS): A centralized system stores all files and changes in a central server. Developers can check out files from the server to work on them and then commit their changes back to the server. Examples of CVCS include Subversion (SVN) and Team Foundation Server (TFS).

  2. Distributed Version Control Systems (DVCS): A distributed system stores a complete copy of the project and its history on the local machine of each developer, rather than a central server. Developers can commit changes locally, create branches, and then push their changes to a central server or exchange changes directly with other developers. Examples of DVCS include Git, Mercurial, and Bazaar.

DVCS are generally favored over CVCS for their offline capabilities, branching and merging capabilities, and strong support for distributed collaboration.

  • Exercises:

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

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

  1. Sign in to your GitHub account and click on the "New repository" button.

  2. Give your repository a name, a brief description, and choose whether you want it to be public or private.

  3. Initialize the repository with a README file, a license, and/or a .gitignore file, depending on your needs.

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

  5. On your local machine, open a terminal window and navigate to the directory where you want to clone the repository.

  6. Use the git clone command followed by the URL of your repository, which you can find on the repository page on GitHub. For example:

     git clone https://github.com/your-username/your-repo-name.git
    

    Replace your-username and your-repo-name with your GitHub username and the name of your repository.

  7. Git will now create a local copy of your repository in the directory you specified. You can now make changes to the files in the repository and use Git to track and manage those changes.

That's it! You have now created a new repository on GitHub and cloned it to your local machine.

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

Steps to make changes to a file in a Git repository and commit those changes:

  1. Open a terminal window on your local machine and navigate to the directory where your Git repository is stored.

  2. Open the file you want to make changes to using your preferred text editor or IDE.

  3. Make the desired changes to the file, save and close it.

  4. Open a terminal window and navigate to the directory where your Git repository is stored.

  5. Use the git status command to see the changes that have been made to the file since the last commit.

  6. Use the git add command followed by the filename to stage the changes. For example, if you changed a file called "index.html", you would use the following command:

     git add index.html
    
  7. Use the git commit command to commit the changes to the repository. You can include a message describing the changes using the -m option. For example:

     git commit -m "Updated the header on the home page."
    

    3.Push the changes back to the repository on GitHub

    1. Use the git push command to push the changes to the remote repository on GitHub. For example:
    git push origin main

This will push the changes to the "main" branch of the repository on GitHub (replace "main" with the name of the branch you want to push the changes to, if applicable).

Thank you,