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

Adinath SalunkeAdinath Salunke
4 min read

(1)what is Git Branching?

A branch is a version of the repository that diverges from the main working project. It is a feature available in most modern version control systems. A Git project can have more than one branch. These branches are a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug, you spawn a new branch to summarize your changes. So, it is complex to merge the unstable code with the main code base and also facilitates you to clean up your future history before merging with the main branch.

Branches allow you to develop features, fix bugs, or safely experiment with new ideas in a contained area of your repository.

(2)Git Revert and Reset?

Git Reset:

The git reset command allows you to RESET your current head to a specified state. You can reset the state of specific files as well as an entire branch. This is useful if you haven't pushed your commit up to GitHub or another remote repository yet.

Git Revert:

Both the git revert and git reset commands undo previous commits. But if you've already pushed your commit to a remote repository, it is recommended that you do not use git reset since it rewrites the history of commits. This can make working on a repository with other developers and maintaining a consistent history of commits very difficult.

Instead, it is better to use git revert, which undoes the changes made by a previous commit by creating an entirely new commit, all without altering the history of commits.

(3)Git Rebase and Merge?

Git Merge

The git merge command will merge any changes that were made to the code base on a separate branch to your current branch as a new commit.

The command syntax is as follows:

--> git merge BRANCH-NAME

For example, if you are currently working in a branch named dev and would like to merge any new changes that were made in a branch named new-features, you would issue the following command:

--> git merge new-features

Imp Note: If there are any uncommitted changes on your current branch, Git will not allow you to merge until all changes in your current branch have been committed. To handle those changes, you can either create a new branch and commit the changes.

Git rebase:

The git rebase command allows you to easily change a series of commits, modifying the history of your repository. You can reorder, edit, or squash commits together.
Typically, you would use git rebase to:

(a)Edit previous commit messages

(b)Combine multiple commits into one

(c)Delete or revert commits that are no longer necessary

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, [hint try git checkout -b dev], swithch to dev branch ( Make sure your commit message will reflect as "Added new feature").

(a)version01.txt should reflect at local repo first followed by Remote repo for review.

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.

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

(b)2nd line>> This is gadbad code. Commit this with message “ Added feature3 in development branch.

(c)3rd line>> This feature will gadbad everything from now. Commit with message “ Added feature4 in development branch.

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

Task 2:

(a)Demonstrate the concept of branches with 2 or more branches with screenshot.

To check the branches use command git branch.

Let's create a new branches to learn how to create new branches.

To create a new branche use command git branch branchname or git checkout -b branchname.

Now switch to Demo1 branch with git checkout command.

(b)add some changes to dev branch and merge that branch in master

Let's verify the master branch with dev branch to check the same contents are there in both branches.

(c)as a practice try git rebase too, see what difference you get

Thanks

Adinath Salunke

0
Subscribe to my newsletter

Read articles from Adinath Salunke directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Adinath Salunke
Adinath Salunke