Deep Dive in Git and GitHub for DevOps Engineers

Vivek ChaudharyVivek Chaudhary
5 min read
  1. What is Git and why is it important?

    Git is a distributed version control system widely used in software development. It's important because it allows developers to track and manage changes to source code, work collaboratively, and maintain different versions of their software efficiently. It helps prevent conflicts, enables branching for parallel development, and provides a complete history of code changes. Git's open-source nature and compatibility with various tools make it a fundamental tool for modern software development.

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

    "Main" and "Master" branches are both commonly used terms in Git for the primary development branch of a repository. The choice between "Main" or "Master" is largely a matter of convention and preference.

    ***"Master"*** was historically the default and most commonly used name for the main branch.

    ***"Main"*** is a more recent convention that some consider to be more inclusive and less tied to historical associations of the word "master."

  3. Difference between Git and GitHub?

    1. Git:

      • Git is a distributed version control system (DVCS) used for tracking changes in source code and managing project history.

      • It's a software tool that allows developers to work on code collaboratively, track changes, and manage different versions of their software locally on their computers.

      • Git is a command-line tool that operates primarily locally and can be used without an internet connection.

    2. GitHub:

      • GitHub is a web-based platform and service built around Git.

      • It provides a platform for hosting Git repositories in a centralized manner, making it easy for developers to collaborate on projects, contribute to open-source software, and manage their code online.

      • GitHub offers features like issue tracking, pull requests, collaboration tools, and a user-friendly web interface for managing Git repositories.

      • It serves as a hosting service for Git repositories, making it accessible to a wider audience, including non-developers.

  4. How do you create a new repository on GitHub

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

    1. Sign In: Go to GitHub and sign in to your GitHub account if you're not already logged in.

    2. Access Your Repositories: Click on your profile picture in the upper right corner and select "Your repositories" from the dropdown menu. This will take you to your repository list.

    3. Create a New Repository:

      • Click the "New" button on the right side of the repository list, or you can click the "New" button on the left sidebar.
    4. Fill in Repository Details:

      • Enter a name for your repository in the "Repository name" field. This should be a unique and descriptive name.

      • You can add an optional description to provide more information about your repository.

      • Choose the visibility for your repository. You can make it public (visible to everyone) or private (accessible only to specific collaborators).

      • You can also choose to initialize your repository with a README file, which is often a good practice.

    5. Choose a License (Optional):

      • You can choose to add a license to your repository. GitHub provides several open-source licenses to choose from.
    6. Choose .gitignore (Optional):

      • You can select a .gitignore file template to help you ignore specific files and directories in your repository.
    7. Choose a License (Optional):

      • You can select a license for your repository. GitHub provides several open-source licenses to choose from.
    8. Click "Create Repository":

      • Review the information you've entered and then click the "Create repository" button. Your new repository will be created.

Once you've created the repository, you'll be taken to the repository's main page. From there, you can add files, manage your repository settings, and collaborate with others by inviting collaborators, creating branches, and making commits. You can also clone the repository to your local machine and start working on your project.

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

    Local and remote repositories are related to version control systems like Git. Here are the key differences and how to connect them:

    Local Repository:

    • A local repository is stored on your computer, and it contains the complete history of a project.

    • You work on files, make commits, and manage versions locally in your development environment.

    • It's not accessible to others by default and is primarily for your personal use.

Remote Repository:

  • A remote repository is stored on a server or a platform like GitHub, GitLab, or Bitbucket.

  • It's a centralized location where you can share your code and collaborate with others.

  • Multiple developers can push and pull changes to and from a remote repository, facilitating collaboration.

Connecting Local to Remote:

  1. Create a Remote Repository:

    • On platforms like GitHub, GitLab, or Bitbucket, create a new repository.
  2. Add the Remote Repository URL:

    • On your local machine, within your local Git repository, use the following command to add a remote repository:
        git remote add origin <remote_repository_url>
  • Replace <remote_repository_url> with the URL of your remote repository.

    1. Push Your Code to the Remote Repository:
  • After adding the remote, you can push your local code to the remote using:

        git push -u origin master
  • The -u flag is used to set up a tracking relationship between your local and remote branches.

Now, your local and remote repositories are connected. You can push your local changes to the remote, pull changes made by others, and collaborate on the same codebase stored in the remote repository.

0
Subscribe to my newsletter

Read articles from Vivek Chaudhary directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vivek Chaudhary
Vivek Chaudhary