#90DaysOfDevOps - Day 9: Deep Dive in Git & GitHub for DevOps Engineers.

ยท

7 min read

Introduction

Today marks the 9th day of the 90DaysDevOps challenge, where we're diving deep into Git and GitHub for DevOps Engineers. We'll start by understanding what Git is and why it matters. We'll also talk about the difference between the Main Branch and the Master Branch, and we'll clarify the dissimilarities between Git and GitHub.

After that, we'll get practical. We'll learn how to set up your name and email for your changes, create a new space for your project on GitHub, link your local work to GitHub, add a new file to your project, and share your updates with GitHub.

Are you ready to begin? Let's jump in!

What is Git and why is it important?

10-Minute Guide to Git Version Control for Testers | by Zhimin Zhan | Medium

Git is a distributed version control system designed to track changes in a projectโ€™s files. Git offers strong support for non-linear development and speed.

Why is it important? Imagine this: You're building something, like a digital tool. After a while, you finish and show it to others as Version 1.0. They like it, but then someone asks for extra things. So, you have to change your creation. You work on it some more, adding the new stuff. After all the changes, you're ready with Version 1.01. People are happy again.

But now, there's a new challenge. Someone else wants different extra things, not the same as before. So, you need to change your creation again. But here's the problem: you've already changed it a lot! So, what can you do? The usual way is tricky and takes a lot of time - undoing everything you did.

Here's where the hero comes in - it's like a special tool called a version control system (think of it like a time machine for your work). It keeps track of every version and changes you make, so you don't have to worry about this tricky situation anymore.

What are Git Branches?

Tutoriel Git : git branch

Imagine you're working on a big project with your team. Git Branches are like making different copies of your project. You can try out new stuff or work on different ideas at the same time without breaking the main project.

Think of it as having separate playgrounds for your ideas. When you change something in one playground (branch), it doesn't change the other playgrounds until you decide to mix them together.

Master/Main branch

The "main branch" or "master branch" is like the main starting point for a project stored in Git. The difference is mostly in what they're called and where they came from:

Master Branch

In the past, "master" was the default name for this main branch in Git. It started with an older system called BitKeeper.

This "master" branch is where the main work happens. People add new things and fix issues here before sharing them with everyone else.

But, because "master" has connections to hurtful things, people are trying to use more respectful words.

Main Branch

To make things better, lots of places are using a friendlier name, "main", instead of "master".

"Main" does the same job as "master". It's where all the important work and changes happen, but with a kinder name that includes everyone.

Difference between Git and GitHub?

Let's break it down: We're putting Git on our computers, and other developers are doing the same. But how do we share our work and talk to each other? That's where GitHub helps. Imagine GitHub as a big meeting place for our work. It's like a supercenter where everyone sends their work, and others get it. This helps us all work together.

Think of GitHub as a powerful computer that holds all our stuff. We send our work to this central place, and others pick it up from there. This way, we're like a team that shares everything in one spot. It's like a cloud service for our work, and it makes it easy for all of us to work on the same project.

GitHub is like a special website that shows our work nicely. It helps us see our work's story and lets us find and fix problems. It's also great for working together with others.

How do you create a new repository on GitHub?

You can refer to the previous Day 8 Task to learn how to create a new repository on GitHub.

Difference between local & remote repository

Git Remote | Learn Git

Local Repository: A local repository is like your personal workspace. It's a folder on your own computer where you keep all the files and changes related to your project. When you work on your project, you make changes in this local repository. It's like your own private playground where you can experiment, create, and modify things without affecting anyone else.

Remote Repository: A remote repository is like a shared hub. It's stored on a server, which is usually on the Internet. This repository is where you and your team members store your work to collaborate. When you want to share your changes with others or get their changes, you do it through this remote repository. It's like a central place where everyone's work comes together.

In simple terms, the local repository is where you do your individual work, and the remote repository is where you all come together to share and combine your work.

Tasks

  1. Set username and email id for git commits

    We use the git config command to set the username and email id to use when you do any git commits. This helps to know who made the commit.

     ubuntu@~$: git config --global user.name "pka2412"
     ubuntu@~$: git config --global user.email "pka2412@gmail.com"
    

    --global sets the configuration values at the user level.

    There are two more levels

    --local sets the configuration values at the repository level.

    --system sets the configuration values at the system level.

  2. Create a repository on GitHub

    Create a new repository 'Devops' on GitHub. Go to your GitHub repositories and click on "New"

    The create repository page opens and enter the details as shown in the figure below. Click on "Create repository"

    The "Devops" repository is created.

  1. Connect your local repository to the repository on GitHub

    There are three ways via HTTPS, SSH, and GitHub CLI to connect the local repository with GitHub. You can refer to the previous Day 8 Task to learn how to connect your local repository to the repository on GitHub.

  2. Create a new file in the local repository

    Create a new file "Devops/Git/Day-02.txt" in the local repository with some content in it.

     #create git directory
     ubuntu@~$:~/Devops$ mkdir git
    
     #create git/Day-02.txt file and add contents to the file
     ubuntu@~$:~/Devops$ echo "This is Day 2 file" > git/Day-02.txt
    
     #display the content of the file
     ubuntu@~$:~/Devops$ cat git/Day-02.txt 
     This is Day 2 file
    
     #check for any changes in the repository
     ubuntu@~$:~/Devops$ git status
     On branch main
     Your branch is up to date with 'origin/main'.
    
     Untracked files:
       (use "git add <file>..." to include in what will be committed)
             git/
    
     nothing added to commit but untracked files present (use "git add" to track)
    
     #add the changes to staging area
     ubuntu@~$:~/Devops$ git add -A
     #again check the status
     ubuntu@~$:~/Devops$ git status
     On branch main
     Your branch is up to date with 'origin/main'.
    
     Changes to be committed:
       (use "git restore --staged <file>..." to unstage)
             new file:   git/Day-02.txt
    
     #commit the changes of git/Day-02.txt file
     ubuntu@~$:~/Devops$ git commit -m "Added day 2 file"
     [main 23ac50c] Added day 2 file
      1 file changed, 1 insertion(+)
      create mode 100644 git/Day-02.txt
     #verify whether our working directory is clean
     ubuntu@~$:~/Devops$ git status
     On branch main
     Your branch is ahead of 'origin/main' by 1 commit.
       (use "git push" to publish your local commits)
    
     nothing to commit, working tree clean
    
  3. Push your local commits to the repository on GitHub

    We will push the changes of the local repository to the repository on GitHub.

     #push the changes of main branch from local repository to GitHub
     ubuntu@~/Devops$: git push origin main
     Enter passphrase for key '/home/ubuntu/.ssh/id_ed25519': 
     Enumerating objects: 5, done.
     Counting objects: 100% (5/5), done.
     Compressing objects: 100% (2/2), done.
     Writing objects: 100% (4/4), 334 bytes | 334.00 KiB/s, done.
     Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
     To github.com:pka2412/Devops.git
        0983dd8..23ac50c  main -> main
    

    To verify we check the "Devops" repository on GitHub. We see a new folder "git" has been created with "Day-02.txt" file in it.

Conclusion

Today, we discovered what Git is and why it's useful. We also learned about the Main Branch and Master Branch and how they're different. We talked about the contrast between Git and GitHub. We found out how to make a new place for our work on GitHub. After that, we did some hands-on stuff: setting our names for changes, making a home for our project on GitHub, linking our personal work to GitHub, adding a new thing to our project, and sharing our changes on GitHub.

"๐ŸŒฑ Keep learning, and spread the knowledge to inspire others. ๐Ÿš€๐Ÿ’ก"

Go back to the main page

ย