Day 9 Task: Deep Dive in Git & GitHub for DevOps Engineers.

Day 9 Task: Deep Dive in Git & GitHub for DevOps Engineers.

Β·

6 min read

What is Git and why is it important?
What is Git and why is it important?
Explain the difference between Git and GitHub?
How do you create a new repository on GitHub?
What is difference between local & remote repository? How to connect local to remote?
Task-1: Set your user name and email address, which will be associated with your commits.
Task-2:Create a repository named "Devops" on GitHub
: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

Introduction

Welcome to Day 9 of our DevOps journey! πŸš€ Today, we'll be taking a deep dive into the world of Git and GitHub. Strap in, because by the end of this blog, you'll not only understand the basics but also have completed some hands-on tasks to reinforce your knowledge.

What is Git? πŸ€”

Git is a distributed version control system that tracks changes in source code during software development. It enables multiple developers to collaborate seamlessly, maintaining a chronological record of modifications.

Let's understand it by using real world example

  • πŸ“š Code Time-Traveler: Git is your code's time-travel machine. It remembers every change so you can go back and fix things. ⏰

  • 🀝 Teamwork Buddy: Think of Git as a dance floor for your code. Lots of people can dance (code) together without tripping over each other. πŸ’ƒπŸ•Ί

  • 🌐 Coding Safety Net: Oops, made a mistake? Git's your superhero cape. Undo, and all's well again! πŸ¦Έβ€β™‚οΈ

Why is Git Important? 🌐

🀝 Seamless Collaboration: Git ensures a smooth dance of multiple developers on the same project, avoiding conflicts and promoting teamwork.

πŸ—ΊοΈ Historical Tracking: It's the code historian, keeping a detailed record of changes, ensuring accountability, and swiftly resolving issues.

🌿 Branching for Innovation: Developers can play in their own sandbox, experimenting with new ideas in separate branches, all while keeping the main project stable.

🌐 Global Contribution: Git's distributed nature fosters a global coding party, bringing diverse minds together, much like the collaborative spirit in projects such as Linux.

✨ Error Reversal Capability: Acting as a safety net, Git allows quick and efficient undoing of changes, providing a fearless space for experimentation and growth. πŸš€πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Some Other Points on it

  • Project Organizer: Keeps your code party organized, so it's not a wild mess. πŸŽ‰

  • Idea Playground: Lets you try new things without messing up your main masterpiece. 🎨

  • Code Harmony Conductor: Like the orchestra leader, making sure everyone plays together without chaos. 🎻🎺

Main Branch vs. Master Branch Puzzle 🧩

Ever wondered about the difference between the "Main" and "Master" branches in Git? Let's demystify it in a simple and playful way! 🎭

Main Branch 🌐

  • Name Evolution: "Main" is the contemporary and more inclusive term replacing "Master."

  • Primary Default Branch: Often set as the default branch when you create a new repository.

  • Symbol of Unity: Reflects the industry's move towards language that is considerate and mindful.

Master Branch πŸŽ“

  • Traditional Term: Historically used as the default branch name.

  • Rooted in Tradition: The term "Master" doesn't carry the same inclusive connotations as "Main."

Difference between Git and GitHub

πŸ€– Git: Think of Git as the wizard behind the scenes, managing your code's history and changes. It's the engine that powers version control, enabling time travel and collaboration.

🌐 GitHub: GitHub is like the cool clubhouse in the cloud where your Git repositories live. It provides a slick, user-friendly interface for collaboration, issue tracking, and team coordination. GitHub is the party venue for your code. πŸš€πŸ’»

Creating a GitHub Repository πŸš€

  1. πŸ”’ Log In to GitHub:

    • Head over to GitHub and log in to your account. If you don't have one, sign up – it's a quick and straightforward process!
  2. πŸ‘€ Access Your Profile:

    • Click on your profile picture in the top right corner to access the dropdown menu.
  3. πŸ“ Go to "Your Repositories":

    • Select "Your repositories" from the dropdown menu.
  4. βž• Click "New":

    • A shiny green button on the right labeled "New" awaits your click.
  5. πŸ–‹οΈ Fill in Details:

    • Name your repository Devops creative! Add a brief description, so others know what your project is all about.
  6. πŸ‘€ Choose Visibility:

    • Decide if your project will be a public spectacle or a private backstage affair.
  7. πŸ“„ Initialize with a README:

    • Opt to start your repository with a README file for an instant project overview.
  8. πŸš€ Click "Create Repository":

    • Finally, hit the green "Create repository" button – your project's grand opening!

Local and Remote Repositories

The mystery of local and remote repositories – the dynamic duo powering collaboration and code magic. πŸ§™β€β™‚οΈβœ¨

Local Repository: 🏠

  • Your Personal Coding Space: Think of your local repository as your cozy home. It's where you do all the coding, experiment with new features, and make changes to your project.

  • No Internet Required: This is your offline haven, unaffected by the cyber waves. Your local changes are safe and sound within the walls of your coding sanctuary.

Remote Repository: 🌐

  • The Cloud Kingdom: Now, imagine the remote repository as a magical cloud kingdom. It's the online version of your project, living on platforms like GitHub, GitLab, or Bitbucket.

  • Global Accessibility: The remote repository is accessible from anywhere with an internet connection. It's where teams collaborate, share ideas, and collectively contribute to the project.

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

Setting up your user name and email address associated with your commits is a crucial step in Git configuration. Follow these simple commands in your terminal:

  1. Set Your User Name:

     git config --global user.name "asifshaikh49"
    

    Replace "Your Name" with your actual name. This helps Git identify who is making the changes.

  2. Set Your Email Address:

     git config --global user.email "asifshaikh@gmail.com"
    

    Substitute "" with the email you use for your Git-related activities. This associates your commits with your email address.

Now, with your user name and email configured, Git will recognize your identity when you make commits.

Task 2 :

Create a Repository on GitHub

  1. Visit GitHub.

  2. Log in to your account.

  3. Click on the "+" sign in the top right corner and select "New Repository."

  4. Name it "Devops."

  5. Optionally, add a description.

  6. Click "Create repository."

Connect Local Repository to GitHub

In your local terminal:

  1. Navigate to your project directory.

     cd project
    
  1. Initialize Git if you haven't already.

     git init
    
  2. Add the GitHub repository as a remote.

     git remote add origin https://github.com/asifshaikh49/Devops.git
    

Create a New File and Add Content

  1. Create the necessary directories and the file.

     mkdir -p Devops/Git
     touch Devops/Git/Day-09.txt
     ls
    
  2. Open the file and add some content.

     echo "Hello, Day 2! DevOps is awesome!" >> Devops/Git/Day-02.txt
     vi Day-09.txt
     echo "Hello, Day 9! DevOps is awesome! another methode"
    

Push Local Commits to GitHub

  1. Add the changes.

     git add .
    
  2. Commit the changes.

     git commit -m "Adding Day-09.txt"
    
  3. Check the status of git:

     git Status
    
  4. Add URL

git remote add origin https://github.com/asifshaikh49/Devops.git
  1. Generate a token :
    • Click on top right corner of your GitHub profile

      • Click on the setting

      • Click on Developer Setting

      • Select the Personal token

      • Select Classic token

      • Copy The link

Push to the GitHub repository.

git remote set-url origin --push https://{TOKEN}@github.com/asifshaikh49/Devops.git
git push -u origin main

Your local changes are now on GitHub. Head to your repository, and you'll find the magic in action

Β