## Day 12 Task: Basic Git & GitHub for DevOps Engineers.

## Day 12 Task: Basic Git & GitHub for DevOps Engineers.

What is Git?

Git is a version control system also known as a global information tracker which allows your files to have version history. With Git, you can keep a record of who made changes to what part of a file, and you can revert back to earlier versions of the file if needed.

practical use

  • Code management

  • Version Control System

  • collaboration

    which acts like a version control system and allows you to collaborate.

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.

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?

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.

  2. A distributed version control system (DVCS) allows developers to "clone" an entire repository, including the entire version history of the project. Imagine you have a group of people working together on a big project, like writing a book or creating a presentation. Each person in the group has a copy of the project files on their computer. Now, they want to collaborate and make changes to these files.

    Exercises:

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

  3. Sign in to GitHub: If you don't have a GitHub account, go to github.com and sign up for one.

  4. Create a New Repository:

    • Once you're logged in, click on the "+" icon in the top right corner of the GitHub dashboard.

    • Select "New Repository" from the drop-down menu.

  5. Set up the Repository:

    • You'll be taken to the "Create a new repository" page.

    • Enter a name for your repository. The name should be descriptive and related to the project you're working on.

    • Optionally, provide a short description of your repository to help others understand what it's about.

    • Choose whether you want your repository to be public (visible to everyone) or private (only visible to you and collaborators). Note that private repositories may require a paid GitHub subscription.

  6. Initialize with a README file (Optional):

    • If you want to add some initial content to your repository, check the "Initialize this repository with a README" option. The README is a markdown file where you can provide essential information about your project, such as what it does, how to use it, etc.
  7. Choose a License (Optional):

    • You can choose an open-source license for your project by clicking on "Add a license" and selecting from the available options. A license helps others understand how they can use, modify, and distribute your code legally.
  8. Create the Repository:

    • Click the "Create repository" button to finalize the creation of your repository.

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

Step 1: Clone the repository (if you haven't done it already):

    git clone <repository_url>
    cd <repository_name>

Step 2: Create or modify a file: Let's say you have a file named "example.txt" in the repository, and you want to make changes to it. You can use any text editor to modify the file.

Step 3: Check the status of the repository: Before committing changes, it's a good practice to check the status of your repository to see which files have been modified.

    git status

Step 4: Stage the changes: Stage the changes you want to commit. In this case, we'll stage the changes made to "example.txt".

    git add example.txt

You can also use git add . to stage all changes in the repository.

Step 5: Commit the changes: Commit the staged changes with a meaningful commit message.

    git commit -m "Add/Modify example.txt file"

Replace "Add/Modify example.txt file" with a descriptive commit message related to the changes you made.

Step 6: Push the changes: If you are working on a remote repository (e.g., on GitHub, GitLab, etc.), you need to push the changes to the remote server to update the repository.

    git push origin main

Replace "main" with the name of your branch if it's different from "main".

3. Push the changes back to the repository on GitHub

Step 1: Verify the remote repository URL: Ensure that your local repository is connected to the correct remote repository on GitHub. You can check this using the following command:

    git remote -v

This will show you the remote repository URL(s) associated with your local repository.

Step 2: Push the changes to GitHub: Use the following command to push the changes from your local branch to the corresponding branch on GitHub. If your branch name is "main," the command will look like this:

    git push origin main

Here, "origin" refers to the name of the remote repository, and "main" is the name of the branch you are pushing to. If your branch name is different, replace "main" with the appropriate branch name.