Day-09 Task: Deep Dive in Git & GitHub for DevOps Engineers

Irfan S MominIrfan S Momin
4 min read
  1. What is Git and why is it important?

    Git is a version control system that helps you manage and track changes in your code.

    It's important because it allows collaboration, keeps a history of changes, and helps prevent chaos in coding projects.

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

    The main difference is mostly in terminology. Historically, "master" was commonly used as the default branch name in Git. However, due to concerns about the term's association with slavery, many projects and platforms now use "main" instead of "master" as the default branch name to promote inclusive language. In terms of functionality, they serve the same purpose as the default branch where the latest changes are typically found.

Can you explain the difference between Git and GitHub?

FeatureGitGitHub
DefinitionA distributed version control system.A web-based platform for hosting Git projects.
FunctionalityManages and tracks code changes.Provides a platform for collaboration, code hosting, and project management.
InstallationNeeds to be installed locally on a computer.Accessed through a web browser; no installation is required for basic usage.
UsageUsed for version control on local machines.Used for collaboration, remote repositories, issue tracking, and more.
RepositoriesCan be local or remote.Hosts remote repositories accessible over the web.
CollaborationSupports collaboration but requires coordination.Facilitates easier collaboration with features like pull requests, issues, and project management tools.
ExamplesGit commands (git init, git commit, etc.).GitHub features (pull requests, issues, forks, etc.).

Git is the version control system itself, while GitHub is a platform that uses Git for collaboration and project management, making it more user-friendly and accessible.

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

    Creating a new repository on GitHub is a straightforward process. Here's a basic step-by-step guide:

    1. Sign in to GitHub:

      • If you don't have an account, you need to sign up for one.
    2. Go to your GitHub dashboard:

      • Once logged in, click on the "+" icon in the top right corner of the page.
    3. Choose "New repository":

      • In the dropdown, select "New repository."
    4. Fill in the repository details:

      • Enter a name for your repository.

      • Choose between public and private visibility (public repositories are visible to everyone, while private ones require a subscription).

      • Initialize with a README if you want to create a repository with an initial README file.

    5. Create the repository:

      • Click the "Create repository" button.

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

FeatureLocal RepositoryRemote Repository
LocationOn your local machine.Hosted on a remote server (e.g., GitHub).
PurposeThe working directory for code changes.Shared space for collaboration and storage.
AccessOnly accessible on your machine.Accessible to multiple users over the internet.
ControlDirect control and autonomy.Shared control, often by a team of contributors.
UsageIndividual development and testing.Collaboration, code sharing, and version control.
CommandsCommon Git commands (e.g., git commit).Git commands for collaboration (e.g., git push).
Example PlatformsA local machine with Git installed.GitHub, GitLab, Bitbucket, etc.

Connecting a local repository to a remote one involves a few steps. Here's a simple guide:

  1. Create a Remote Repository:

    Create a repository on a platform like GitHub.

  2. Navigate to Your Local Repository and Initialize Git

    #git init

  3. Add a Remote Link:

    Use the following command to add a remote link to your local repository. Replace <remote_repository_url> with the actual URL of your remote repository.

    #git remote add origin <remote_repository_url>

  4. 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.

  5. Push Your Changes to the Remote Repository:

    If you have existing code in your local repository, you can push it to the remote repository using:

    #git push -u origin master

    Replace "master" with your branch name if it's different.

    Now, your local repository is connected to the remote one.

Task-1:

Task-2:

  • Create a repository named "Devops" on GitHub

    click on new

  • Connect your local repository to the repository on GitHub.

  • Create a new file in Devops/Git/Day-02.txt & add some content to it

  • Push your local commits to the repository on GitHub

0
Subscribe to my newsletter

Read articles from Irfan S Momin directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Irfan S Momin
Irfan S Momin

A Foodie Software Engineer's Journey to Eating Healthy and Learning Something New Every Day