Deep Dive in Git & GitHub for DevOps Engineers

Deep Dive in Git & GitHub for DevOps Engineers

#90DaysofDevOps Challenge - Day 9

Table of contents

No heading

No headings in the article.

▶What is Git?

It is a distributed, open-source version control system.

Git stores your source code and its full development history locally in a repository.

There are some key benefits of the use of Git:

Historical Change Tracking – You can review a graph of how your commits have changed over time, see when and by whom changes were made, and revert to a previous commit if needed. This history makes it easier to identify and fix bugs.

Work as a Team – You can easily share your code with teammates for review before you commit or merge back to the main working branch. Additionally, the branching and review capabilities enable simultaneous development. Multiple people can work on the same file and resolve differences later.

Improve Team Speed & Productivity – It makes it easy for your team to track changes to your code. You can keep the focus on writing code instead of spending time tracking and merging different versions across your team.

Availability and Redundancy – Git is a distributed VCS which means that you can work offline and commit your changes when you are ready.

Git Is the Industry Standard – It is popular and integrated into many development environments (IDEs), and many popular developer tools including Jenkins. There are many free Git resources available.

▶What is a Branch? What is the difference between Main and Master?

A branch is a separate line of development within a git repository. When a repository is first created, it has a single branch called “master”. The master branch is considered to be the canonical branch, and all other branches are created from it.

When a change is made to a file in a Git repository, that change is made to the current branch. If the current branch is master, then the change is made to master. If the current branch is a different branch, then the change is made to that branch.

Changes made to a branch do not affect the master branch or any other branch. This allows developers to experiment with new changes without affecting the main codebase.

Once a change has been made to a branch, it can be merged into the master branch. This will apply the changes from the branch to the master branch.

Merging branches is a common practice in Git*, and is used to combine the changes from multiple branches into a single branch. The idea is that you should not make changes directly to the main branch, but test them thoroughly on other branches first, before incorporating them into the main branch.*

In other words, the master branch is the main branch. Because in October 2020, the GitHub company changed the term from “master” to “main”.

▶What are the main differences between Git and GitHub?

In summary, these are the main differences:

▶GitHub create an account to be able to create a repository

To create an account on GitHub, you will be asked for some personal information like your name, confirm your email, set a username and password, and your account should be set up in minutes.

▶Create a GitHub repository

After you create your GitHub account, click on the + button and select a new repository. After that, type the repository name and add a simple description. It will create an empty public repository.

After creating the repository on GitHub, it will provide a detailed guide on how to clone, add remote, and initialize a Git project.

▶Setting your username and email globally in Git

Git usernames and emails are of two types, one is used for Git accounts globally, and the other is set on individual projects as per developers’ preference.

To set username:

$ git config --global user.name "<username>"

To set the user’s email address:

$ git config --global user.email "<email>"

To check the username and email configuration:

$ git config user.name
$ git config user.email

To connect from my local repository to the DevOps repository on GitHub, then create 3 files called Readme.md and Day9.txt add some content inside them, and also add a .jpg file to this repository. To complete, push the local commits to the repository on GitHub.

$ echo "# devops" >> README.md
$ git init
$ git add README.md
$ git add Git-Github.jpg 
$ git commit -m "Day9 DevOps Zero to Hero"
$ git branch -M main
$ git remote add origin https://github.com/fjblsouza/devops.git
$ git push -u origin main
$ echo "# devops" >> Day9.txt
$ git add Day9.txt
$ git commit -m "Adding new file"
$ git branch -M main
$ git push -u origin main

This was a simple nutshell about Git and GitHub for DevOps Engineers. I hope this content is helpful.