Deep Dive in Git & GitHub for DevOps Engineers

ยท

4 min read

1. What is Git and why is it important?

Git is a distributed version control system (VCS) that allows you to track changes made to files and directories. Unlike its predecessor, Subversion, which maintains a centralized repository, Git stores a complete history of changes locally, enabling decentralized collaboration. This decentralized nature empowers developers to work independently, merge changes seamlessly, and revert to previous versions if needed.

Why is Git important?

  1. Version Tracking: Git meticulously tracks every change made to your code, allowing you to trace the evolution of your project and revert to previous versions if necessary.

  2. Collaboration: Git facilitates seamless collaboration among developers, enabling them to work on different parts of the codebase simultaneously without conflicts.

  3. Branching: Git's branching feature allows you to create independent lines of development without affecting the main codebase. This enables experimentation and feature development without disrupting the main branch.

2. What is the difference between Main Branch and Master Branch?

In the context of Git, the main branch and master branch were historically synonymous, both representing the primary branch of the codebase. However, in recent years, the term "main" has been adopted by many projects as a more inclusive alternative to "master."

Both branches serve as the foundation for development, and changes made to them are considered permanent and integrated into the project's history. Developers work on the main branch, making changes and committing them to maintain the project's core functionality.

3. Can you explain the difference between Git and GitHub?

Git and GitHub are two distinct tools that play complementary roles in version control.

Git is a distributed version control system (VCS) that allows you to track changes to your code locally and collaborate with others. It stores a complete history of changes on your local machine, enabling you to work offline and revert to previous versions if needed.

GitHub, on the other hand, is a cloud-based hosting service for Git repositories. It provides a web interface and a set of tools for managing and collaborating on code projects. GitHub allows you to store your Git repositories online, share them with others, and track changes made by collaborators.

In essence, Git is the tool you use to manage your code locally, while GitHub is the platform where you store and collaborate on your Git repositories.

4. How do you create a new repository on GitHub?

  1. Sign up for a GitHub account: If you haven't already, create a free GitHub account.

  2. Navigate to the "New" dropdown menu: Once logged in, click on the "+" icon in the top right corner and select "New Repository."

  3. Provide repository details: Give your repository a name, add a brief description, and choose whether it should be public or private.

  4. Initialize the repository: Click on the "Create repository" button to finalize the repository creation.

5. What is the difference between local and remote repositories? How to connect local to remote?

A local repository is a copy of a repository stored on your local machine. It allows you to work on your code without an internet connection and maintain a complete history of changes.

A remote repository is a copy of your repository stored on a remote server, such as GitHub. It allows you to share your code with others, collaborate with them, and access your code from anywhere with an internet connection.

Verify the Connection:

To verify that the remote repository is correctly linked, you can use:

git remote -v

This should display the fetch and push URLs for the remote repository.

To connect your local repository to a remote repository, use the git remote add command followed by the remote repository's URL. For example, to connect your local repository to the remote repository at <remote_URL>, use:

git remote add origin <remote_URL>

Once connected, you can push changes from your local repository to the remote repository using the git push command. For example, to push all changes to the origin remote, use:

git push origin

This will transfer your local changes to the remote repository, making them available to others.

Day 09 of 90daysofDevOps challenge:

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

# git config --global user.name "<user_name>"
# git config --globa user.email "<user_email_id>"

Task 2: refer to my GitHub and check for Devops repository. ๐Ÿ˜‰

ย