Day 10 Task: Advance Git & GitHub for DevOps Engineers.

Day 10 Task: Advance Git & GitHub for DevOps Engineers.

In today task we will learn all about Advance Git & GitHub for DevOps Engineers:-

We will learn about all these:-

  1. Git Branching
  2. Git Revert and Reset
  3. Git Rebase and Merge

Let’s Start Today’s topics:-

What is Git Branching?

Git, branches are a part of your everyday development process. Git branches are effectively a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug — no matter how big or how small — you spawn a new branch to encapsulate your changes.

Git Branching

What is Git Revert?

The git revert command is a forward-moving undo operation that offers a safe method of undoing changes. Instead of deleting or orphaning commits in the commit history, a revert will create a new commit that inverses the changes specified. Git revert is a safer alternative to git reset in regards to losing work.

Let’s understand by the piratical:-

The syntax to revert a Git commit and undo unwanted changes is simple. All developers need to do is issue the git revert command and provide the ID of the commit to undo:

We will start with a git init command to create a completely clean repository:

With the repository initialized, we’ll add three files to the repo. Each time a new file is created, we add it to the Git index and create a new commit with a meaningful message.

A quick directory listing following the initial command batch shows three files in the current folder: By using ls command

A call to the git reflog command will show us our current commit history:

How to revert a Git commit

What do you think would happen if we did a git revert on the second commit with ID 04ac80d ? This was the git commit that added the beta.html file.

The git revert command will undo only the changes associated with a specific commit. In this git revert example, the second commit added the beta.html file. When we revert said Git commit, the only file removed from our repository is beta.html.

What is Git reset?

Git reset is a powerful command that is used to undo local changes to the state of a Git repo. Git reset operates on “The Three Trees of Git”. These trees are the Commit History ( HEAD ), the Staging Index, and the Working Directory. There are three command line options that correspond to the three trees.

What is Git Rebase?

Rebasing is a process to reapply commits on top of another base trip. It is used to apply a sequence of commits from distinct branches into a final commit. It is an alternative of git merge command. It is a linear process of merging.

In Git, the term rebase is referred to as the process of moving or combining a sequence of commits to a new base commit. Rebasing is very beneficial and it visualized the process in the environment of a feature branching workflow.

It is good to rebase your branch before merging it.

Generally, it is an alternative of git merge command. Merge is always a forward changing record. Comparatively, rebase is a compelling history rewriting tool in git. It merges the different commits one by one.

Suppose you have made three commits in your master branch and three in your other branch named test. If you merge this, then it will merge all commits in a time. But if you rebase it, then it will be merged in a linear manner. Consider the below image:

The above image describes how git rebase works. The three commits of the master branch are merged linearly with the commits of the test branch.

Syntax:

$git rebase

if there are some conflicts in the branch, resolve them, and perform below commands to continue changes:

$ git status

What is Git Merge?

Git merge is a command that allows developers to merge Git branches while the logs of commits on branches remain intact.

The merge wording can be confusing because we have two methods of merging branches, and one of those ways is actually called “merge,” even though both procedures do essentially the same thing

Task:1

:- Add a text file called version01.txt inside the DevOps/Git/ with “This is first feature of our application” written inside. This should be in a branch coming from master,

Our first Point of task is completed, now we proceed Further….

Git command Use for it: -

cd: change directory

cat :Read data from file

git init :creates a new Git repository

git status: display the state of the working directory and the staging area

: - switch to dev branch (Make sure your commit message will reflect as "Added new feature").

Git command Use for it: -

git add . :- add changes to the working directory

git commit :- create a snapshot of the staged changes along a timeline of a git project

git checkout -b :- to change the branch

:- version01.txt should reflect at local repo first followed by Remote repo for review.

Git command Use for it: -

git remote add origin :-Validate the existence of your local Git repository

git push -u origin :- push term refers to upload local repository content to a remote repository.

\==> Add new commit in dev branch after adding below mentioned content in DevOps/Git/version01.txt: While writing the file make sure you write these lines

1st line>> This is the bug fix in development branch and Commit this with message “Added feature2 in development branch”

First we will add first line in the version01.txt file …..

Our file is added successfully after that we will commit it by giving message “Added feature2 in development branch”

2. add second line >>> This is gadbad code and commit this with message “Added feature 3 in development branch”

By using nano command be will add the second line and after that we will commit it.

3. add third line >>> This feature will gadbad everything from now and commit with message “Added feature 3 in development branch”

In this same as 2 we will add and commit

Next our task is…..

Restore the file to a previous version where the content should be “This is the bug fix in development branch

In this we use command git log and git checkout  — —

Task 2

Demonstrate the concept of branches with 2 or more branches with screenshot.

In this task we will discuss all about branches ..

By default there is master branches

First we will made one file that is on master branch and we will add and commit that file to dev branch …

we had init the file and after that we will switch to dev branch….

All the task has been completed…

\===> Add some changes to dev branch and merge to master branch

now we make new directory git merge and add one file merge.txt and after that we will init that file and and add , after adding we commit that file.

After that we checkout master branch and switch to dev branch and do some changes and after we add and commit that file,

After we switch to master branch and write in our file that we will merge file , after that we will add and commit

Now we will merge the both branches by using command git merge

Now we merge both file .

Thanks for reading….

Did you find this article valuable?

Support Dev Cloud by becoming a sponsor. Any amount is appreciated!