#Day9 : Deep Dive in Git & GitHub for DevOps Engineers. #90DaysofDevOps

#Day9 : Deep Dive in Git & GitHub for DevOps Engineers. #90DaysofDevOps

What is Git and why is it important?

Git is one of the most popular Version Control System

It takes code and stores it in database-like files which are called repositories in Git. Git records all the changes that are made and tells when and why changes were made to a particular file. It also specifies who made changes to the particular file.

If anything goes wrong, we can revert the file to the earlier stage

Need:

Without a Version Control System(Git referred here) when working together, it would be needed to constantly store code in small files and be shared over email to merge the code making it very unscalable and inefficient, especially with multiple users working on it.

In short Git helps to track code history and work together.

What is difference Between Main Branch and Master Branch?

There is no major difference between the Main Branch and Master Branch in Github. Before 2020, Master branch was used as the default branch, However, after that Github added main branch as the default branch moving away from the term Master.

However, if we still commit and push changes to master, it will create a branch called master and push the changes to that branch as it does not essentially exist.

Can you explain the difference between Git and GitHub?

  1. Git is software that can be downloaded and installed on the system

    GitHub is hosted on the cloud

  2. Git can be used offline

    GitHub is webpage based and hence can only be used online.

  3. Git is independent and can be used without GitHub

    GitHub cannot be used without using git.

  4. Git is used for Version Control and sharing

    GitHub is used for centralized hosting on the cloud

  5. Git has no Graphical User Interface

    GitHub has a Graphical User Interface

  6. Git has a command line and has different commands such as git add, git commit, git Push

    GitHub is a web-based service and has no command line

  7. Git is open-source

    GitHub has both free-tier and paid versions

  8. The competitors of git are mercurial, supervison, IBM, clearcase

    GitHub competitors are GitLab.

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

    1. Login to the GitHub account.
  1. Go to the main page.

  2. Go to repositories.

  3. Click on new repository in top right corner.

  4. Enter a repository name.

  5. Select whether the repository should be private or public.

    Public repository: It is accessible by other people that use git too.

    Private repository: It is not accessible by anyone other than the repository owner.

  6. Select the checkbox to "Initialize this repository with a README" (optional).

  7. Choose a license if you like (optional).

  8. Click "Create repository".

What is difference between local & remote repository? How to connect local to remote?

The local Git repository is located on your local machine.

On the other hand, the remote repository or Central repository is the one that is hosted on GitHub.

We can make changes, add and commit changes to the local repository but it does not make changes to the remote repository. The changes are made to the remote repository only after we push the changes using git push

Tasks:

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

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

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

To check :

git config --list

Create a repository named "Devops" on GitHub

Connect your local repository to remote repository

Go to the repository and copy the URL.

In local git, use command:

git remote add origin <URL>

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

Go to Devops directory

mkdir -p git/day_02.txt

This will make a directory "git" and a text file "day_02" inside it.

Now add some text to the text file.

After this, use:

git add .

This will add all changes that are made to the local repository.

Now use:

git commit -m "<note>"

This will commit file to the local repository.

Push your local commits to the repository on GitHub.

git push -u origin master

-u in the following command means -upstream

Check it using:

git-branch

We can also check it on the GitHub account.