Deep Dive in Git & GitHub for DevOps Engineers.

Deep Dive in Git & GitHub for DevOps Engineers.

What is Git and why is it important?

Git is a distributed version control system (VCS) used for tracking changes in source code during software development. Created by Linus Torvalds in 2005, Git has become one of the most popular version control systems due to its efficiency, flexibility, and powerful branching and merging capabilities.

Here are some key aspects of Git and why it's important:

  1. Version Control: Git tracks changes made to files, allowing developers to revert to previous versions, compare changes over time, and collaborate with others simultaneously on the same codebase.

  2. Distributed Development: Each developer working on a project has a local copy of the entire repository, enabling them to work offline and independently. Changes can be shared and merged later.

  3. Branching and Merging: Git allows for easy creation of branches, enabling developers to work on separate features or fixes without affecting the main codebase. Merging branches back into the main codebase is seamless, facilitating collaboration.

  4. Security and Integrity: Every change made in Git is tracked using a secure cryptographic hash. This ensures the integrity of the codebase and helps prevent loss of data.

    What is difference Between Main Branch and Master Branch??

    The terms "main" and "master" have historically been used interchangeably in Git to refer to the primary branch in a repository where the main line of development occurs.

    In practical terms, both "main" and "master" branches serve the same purpose: they represent the default branch in a Git repository, where the main development work takes place, and from which other branches (such as feature branches) are typically created and merged.

    The transition from "master" to "main" is more of a naming convention change and doesn't affect the functionality or capabilities of Git itself. It's about promoting inclusivity and using language that aligns with more respectful and inclusive practices within the development community.

Can you explain the difference between Git and GitHub?

  1. Git:

    • Definition: Git is a distributed version control system designed for tracking changes in source code during software development. It is a command-line tool that enables developers to manage and collaborate on projects efficiently.

    • Functionality: Git allows users to create repositories, track changes, create branches, merge code, and revert to previous versions. It operates locally on a developer's machine, providing a version control system that doesn't require a centralized server.

  2. GitHub:

    • Definition: GitHub is a web-based hosting service and platform built around Git. It provides a centralized cloud-based platform for hosting Git repositories and collaborating on code.

    • Functionality: GitHub offers features like repository hosting, collaborative tools for code review, issue tracking, project management, and team collaboration. It allows multiple developers to work together on a project, manage code contributions, and maintain a centralized repository accessible over the internet.

How do you create a new repository on GitHub?

To create a new repository on GitHub, follow these steps:

  1. Sign in to GitHub: Go to https://github.com/ and sign in to your GitHub account.

  2. Navigate to your profile: Click on your profile icon at the top right corner of the page and select "Your repositories" from the dropdown menu.

  3. Create a new repository: Once you're on the "Your repositories" page, click on the green button labeled "New" on the right side of the page. Alternatively, you can click on the "+" icon in the top right corner of the page and select "New repository" from the dropdown.

  4. Fill in repository details: You'll be taken to a page where you can fill in details for your new repository:

    • Repository name: Enter a unique name for your repository.

    • Description (optional): Add a brief description to explain the purpose of the repository.

    • Public or Private: Choose whether you want the repository to be public (visible to everyone) or private (accessible only to specified collaborators).

    • Initialize this repository with a README: Optionally, select this checkbox if you want to initialize the repository with a README file. It's a good practice to check this box, especially if you're starting a new project.

  5. Choose other settings (optional): You can configure additional settings such as adding a .gitignore file (specifies which files should be ignored by Git) and choosing a license for your project.

  6. Create the repository: Click on the green button labeled "Create repository" at the bottom of the page. This action will create your new repository on GitHub.

What is difference between local & remote repository? How to connect local to remote?

  • Local Repository: This refers to the repository that exists on your local machine. When you clone a repository from a remote location or initialize a new repository using Git, you create a local repository. This local copy allows you to work on files, create branches, commit changes, and manage version history without needing an internet connection or interaction with a central server.

  • Remote Repository: A remote repository is hosted on a remote server, which could be on platforms like GitHub, GitLab, Bitbucket, or a private server. It serves as the centralized location where your local changes can be shared and collaborated on with others. Remote repositories are beneficial for team collaboration, backup, and sharing code changes among multiple developers.

To connect a local repository to a remote one (e.g., on GitHub), you'll typically follow these steps:

  1. Create a Remote Repository:

    • On a platform like GitHub, GitLab, or Bitbucket, create a new repository. This step generates a URL that you'll use to connect your local repository to the remote one.
  2. Locate the Remote Repository URL:

    • On the repository's page on the remote platform, find the URL or SSH link for your repository. It's usually provided on the repository's main page.
  3. Link Local Repository to Remote Repository:

    • In your local terminal or Git GUI tool, navigate to your local repository using the command line or graphical interface.