Deep Dive in Git & GitHub for DevOps Engineers.

Deep Dive in Git & GitHub for DevOps Engineers.

Day-9 with #90DaysOfDevops

What is Git and why is it important?

Git is a version control system that allows developers to collaborate on code and track changes made to the codebase over time. It is important because it helps developers work together on the same project without interfering with each other's work, and makes it easier to manage and maintain large codebases.

What is the difference Between Main Branch and Master Branch?

The terms "Main Branch" and "Master Branch" are often used interchangeably but refer to the same thing - the default branch in a Git repository. Some organizations have moved away from using the term "Master" due to its association with slavery, and have instead opted for more neutral or inclusive terminology such as ''Main''.

Can you explain the difference between Git and GitHub?

Git is a tool that helps people who write computer programs keep track of changes they make to their code. It's like having a time machine for your code - you can go back in time and see what your code looked like at different points in the past. Git is a command line tool that you can use on your own computer.

GitHub is a website where people can store their code using Git. So instead of managing changes to their code on their own computer, they can store it on GitHub and collaborate with others. It's kind of like a library for code - people can share their code with others and work together on projects.

Think of Git as a hammer, and GitHub as a toolbox. You need a hammer to build things, but a toolbox helps you organize your tools and makes it easier to work with them. Similarly, you need Git to manage your code changes, but GitHub makes it easier to collaborate with others and store your code in the cloud.

How do you create a new repository on GitHub?

Here are the steps to create a new repository on GitHub:

  1. Go to the GitHub website (github.com) and log in to your account.

  2. In the upper-right corner of the screen, you'll see a "+" icon. Click on it and select "New repository" from the dropdown menu.

  3. On the "Create a new repository" page, you will need to fill out some information about your repository:

    • Give your repository a name.

    • You can also give it a description if you'd like.

    • Choose whether you want your repository to be public (visible to everyone) or private (only visible to people you grant access to).

    • If you want to include a README file in your repository, check the box labeled "Initialize this repository with a README".

    • You can also choose to add a .gitignore file and/or a license to your repository.

Once you have filled out all the necessary information, click on the "Create repository" button at the bottom of the page.

What is the difference between local & remote repositories? How to connect local to remote?

A local repository is a copy of a Git repository that is stored on your computer, while a remote repository is a copy that is stored on a server such as GitHub. The main difference between them is that the local repository is located on your computer and the remote repository is located on a server. A local repository can only be accessed by the person who created it, whereas a remote repository can be accessed and collaborated on by multiple users.

To connect a local repository to a remote repository, you can use the "git remote" command to add a remote repository URL to your local repository. Here are the steps to connect a local repository to a remote repository on GitHub:

  1. Create a new repository on GitHub (if you haven't already) by following the steps in my previous response.

  2. Copy the URL of your new repository from the GitHub website.

  3. Open up your local repository using a terminal or command prompt.

  4. In the terminal or command prompt, type the following command:

     git remote add origin <URL of your new repository>
    

    This command tells Git to add a remote repository named "origin" and link it to the URL you copied in Step 2.

  5. To verify that your local repository is connected to your remote repository, type the following command:

     git remote -v
    

    This command will show you a list of all the remote repositories that your local repository is connected to.

Now you have successfully connected your local repository to your remote repository on GitHub! You can now use commands like "git push" and "git pull" to sync changes between your local and remote repositories.