From Novice to Expert: Git and GitHub Deep Dive

ยท

4 min read

Today, we're going to explore the core of version control- Git and GitHub. If you've been with us so far, you've already started learning about these important tools. Now, we're going to dive deeper into Git and GitHub to boost your DevOps skills.

What is Git?

Git is a distributed version control system (DVCS) that empowers developers to manage and track changes to their codebase.

Why Git?

Now, you might wonder why Git is the go-to choice for version control among DevOps engineers. Here are some compelling reasons:

  1. Efficiency: Git is renowned for its speed. Common version control operations like commits, branching, and merging are lightning-fast, thanks to its local repository setup.

  2. Branching and Merging: Git excels in branching and merging, enabling clean development workflows. Feature branches, bug fixes, and code reviews are a breeze.

  3. Collaboration: With Git, collaborating on projects is smooth, even across distributed teams. You can work on your local copy, push changes to a central repository, or directly pull from colleagues' repositories.

  4. Security: Git enhances security through access control mechanisms and cryptographic keys. Your project's integrity is maintained even if a developer's machine is compromised.

What is the difference Between Main Branch and Master Branch?

The terms "main branch" and "master branch" are often used interchangeably in version control systems like Git.

However, there's a shift in terminology due to cultural sensitivity and inclusivity concerns:

  1. Master Branch:

    • Historically, "master" was commonly used to denote the default or primary branch in Git repositories.

    • In many projects and organizations, "master" was the branch where the main development and integration work took place.

  2. Main Branch:

    • "Main" is an alternative term that has gained traction to replace "master" in version control terminology.

    • It is often used to describe the primary or default branch, serving the same purpose as the "master" branch.

Difference between Git and GitHub:

GitGitHub
Distributed Version Control System (DVCS)Web-based platform and service
Helps developers track changes in their code and collaborate with others.Provides a platform for hosting, sharing, and collaborating on Git repositories.
Git is installed and run on your local machine.GitHub hosts remote repositories on its servers.
Git operates offline.GitHub operates online.
Git is open source.GitHub is a cloud-based service that offers both free and paid plans.

How do you create a new repository on GitHub?

  • Go to GitHub (https://github.com).

  • Log in to your GitHub account.

  • Click on the "+" icon in the top right corner and select "New repository."

  • Fill in the repository name, description, and other settings.

  • Choose the repository visibility (public or private).

  • Click "Create repository."

What is the difference between local & remote repositories?

Local Repository:

  • A local repository is a copy of a Git repository that resides on your local machine. It contains all the project files, version history, and branches.

  • You interact with the local repository using Git commands on your computer. This allows you to make changes, create branches, commit changes, and manage your code offline.

Remote Repository:

  • A remote repository is a copy of a Git repository hosted on a remote server, such as GitHub. It serves as a central hub for collaboration and sharing code with others.

  • Remote repositories are used for team collaboration, backup, and sharing code with contributors. They enable multiple people to work on the same project, share their changes, and track progress.

  • When you push changes from your local repository to a remote repository, others can access your work and collaborate with you.

How to connect local to remote?

To connect your local repository to a remote repository, follow these steps:

  1. Create a Remote Repository: First, create a remote repository on a platform like GitHub.

  2. Link a local Repository to a Remote Repository:

    • Open your local repository in a terminal.

    • Use the git remote add command to connect your local repository to the remote repository. You'll specify a name for the remote repository (commonly named "origin") and the URL of the remote repository.

      git remote add origin https://github.com/yourusername/your-repository.git

  3. Push Your Code: To send your local code to the remote repository, use the git push command. You'll specify the remote repository's name (e.g., "origin") and the branch (here "main") you want to push.
    git push origin main

Task-1:

Task-2:

  • Create a repository named "Devops" on GitHub.

  • Connect your local repository to the repository on GitHub.
    cd /path/to/your/git/project git init
    git remote add origin https://github.com/yourusername/Devops.git

  • Create a new file in Devops/Git/Day-02.txt & add some content to it.
    git add .
    git commit -m "<your_commit_message>"
    git push

  • Push your local commits to the repository on GitHub.

Thank you!

ย