Day 9 - Deep Dive in Git & GitHub for DevOps Engineers
Tags: devops, github, git, 90daysofdevops
Published: 2024-06-10 13:02:58

**1.What is Git and why is it important?**
Git is a distributed version control system that is widely used in software development to manage source code and track changes made to it over time.

Basically, Git allows developers to collaborate on software projects in a highly organized and structured way. With Git, developers can create their own local working copy of a project, make changes to it, and then merge those changes back into the central repository. Git makes it easy to keep track of which changes were made by whom, when they were made, and why they were made.

**Here are a few reasons why Git is important:**
**Collaboration:** Git makes it easy for developers to collaborate on projects, even if they are located in different parts of the world. Multiple developers can work on the same codebase simultaneously without interfering with each other's work.

**Version control:** Git gives developers the ability to easily track changes to code over time and revert to earlier versions if necessary. This is important for maintaining the integrity of the codebase and ensuring that changes can be rolled back in case of errors or bugs.

**Branching and merging:** Git allows developers to create branches, which are separate copies of the codebase that can be modified independently. This allows for experimentation and testing of new features without affecting the main codebase. Branches can be merged back into the main codebase once the changes have been tested and approved.

**Integration with other tools:** Git can be integrated with other tools in the software development process, such as continuous integration (CI) servers, issue tracking systems, and code review tools. This allows for a highly automated and streamlined development workflow.

Overall, Git is important because it provides developers with a powerful set of tools for managing code, collaborating on projects, and ensuring the quality and integrity of their work.

**2.What is difference Between Main Branch and Master Branch?**
In Git, "main" and "master" branches are both commonly used to refer to the primary branch of a repository that contains the latest stable and production-ready code. However, there is no functional difference between the two terms and they can be used interchangeably.

The term "master" has historically been used in many software development projects to refer to the main branch. However, this term has been criticized for its potentially problematic connotations, particularly given the ongoing conversation about systemic racism and bias in the tech industry. As a result, many developers are now transitioning to using the term "main" instead of "master" to refer to the primary branch of their Git repository.

Many organizations and projects are now officially adopting "main" as the primary branch name, while others continue to use "master". In either case, the functionality of the branch remains the same regardless of whether it is named "main" or "master".

**3.Can you explain the difference between Git and GitHub?**
Git is a distributed version control system that is used to manage source code and track changes made to it over time. Git provides developers with a powerful set of tools for collaborating on code, maintaining version history, and ensuring the integrity and quality of the codebase.

GitHub, on the other hand, is a web-based hosting service for Git repositories. Essentially, GitHub provides a centralized platform for developers to store and share their Git repositories with others. In addition to hosting Git repositories, GitHub provides a range of features and tools that make it easy for developers to collaborate on code, track issues and bugs, and manage project workflows.

**4.How do you create a new repository on GitHub?**
To create a new repository on GitHub, you can follow these steps:

1.Log in to your GitHub account and click on the "+" icon in the upper right-hand corner of the page.

2.Select "New repository" from the dropdown menu.

3.Enter a name for your repository in the "Repository name" field. This name should be descriptive and memorable, and may include a combination of letters, numbers, and hyphens.

4.Optionally, you can add a description for your repository that describes its purpose, contents, or any other important information.

5.Choose whether your new repository will be public or private. Public repositories are visible to everyone, while private repositories can only be accessed by you and any collaborators you invite.

6.If you have an existing repository that you want to import into GitHub, you can choose the "Import repository" option and follow the prompts to import your code.

7.After you have set your options, click on the "Create repository" button to create your new repository.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6n8kiuc56i7wxrnl30fz.png)

**5.What is difference between local & remote repository? How to connect local to remote?**
A local repository is a copy of a Git repository that is stored on the developer's local machine, while a remote repository is a copy of a Git repository that is hosted on a remote server. The primary difference between the two is their location, with the local repository stored on the developer's computer and the remote repository stored on a server accessible via the internet or a local network.

**To connect a local repository to a remote repository, you can follow these steps:**

First, create a new repository on your remote Git server. This server could be GitHub, GitLab, Bitbucket, or any other Git hosting service.

Next, navigate to your local repository on your machine and open up a command-line interface.

Use the following command to add the remote repository to your local repository:

`git remote add origin [remote repository URL]`

This command tells Git to associate the remote repository with the name "origin".

Next, push your local repository to the remote repository using the following command:

`git push -u origin master`

This command tells Git to push the "master" branch of your local repository to the "origin" remote repository.

**Task-1:**
Set your user name and email address, which will be associated with your commits.

To set user name and email address to be associated with commits in Git, use the following commands, replacing the user name and email address with your own:
  

```
git config --global user.name "Your Name"
  git config --global user.email "youremail@gmail.com"

```

**Task-2:**
1.Create a repository named "Devops" on GitHub

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p7zinae3winbvjivf5d1.png)

2.Connect your local repository to the repository on GitHub.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z4w00sfwacx7snela2ad.png)

3.Create a new file in Devops/Day-09.txt & add some content to it

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/coc6gg3r4b3ujrh2udao.png)

4.Push your local commits to the repository on GitHub