Day 10: Advance Git & GitHub

Day 10: Advance Git & GitHub

·

4 min read

#Day10 of #90DaysofDevops challenge

Click here to view Day 10 task.

Git Branching

Git branching is a feature of the Git version control system that allows developers to create multiple parallel versions of a project, called "branches". Each branch is a separate line of development that can be worked on independently of the other branches. This allows multiple developers to work on different features or bug fixes at the same time without interfering with each other's work.

Git Revert and Reset

Git revert and reset are both commands used in the Git version control system to undo changes made to a repository. However, they work in different ways and have different use cases.

Git revert creates a new commit that undoes the changes made in a previous commit. This means that the original commit is still in the repository history, but its changes have been undone. This is useful when you want to undo a specific commit while keeping the history intact. When you use git revert, you are creating a new commit that undoes the changes of a previous commit, which means that you will still have a history that includes both the original commit and the revert commit.

On the other hand, git reset moves the branch pointer to a previous commit, effectively removing any commits made after that point. This means that all the changes made in those commits will be lost. This command is more drastic than git revert, as it completely removes any changes made after the specified commit. Git reset can be useful when you want to undo all the changes made after a certain point and start over from there.

What is Git Rebase?

Git rebase is a Git command used to integrate changes from one branch into another branch. It works by moving the changes in one branch to a new base, which can be another branch or a specific commit. The result is a new branch that incorporates the changes from the original branch, but with a different base.

The main difference between git merge and git rebase is that git merge adds the changes from one branch to another, creating a new merge commit, while git rebase moves the changes from one branch to another, rewriting the history of the branch being rebased.

To use git rebase, you typically start by checking out the branch that you want to rebase, and then running the command "git rebase <branch>".

What is Git Merge?

'git merge' is a Git command used to combine changes from one branch into another branch. It creates a new merge commit that has two parent commits - the most recent commit of the current branch and the most recent commit of the branch being merged.

The basic idea behind merging is to take the changes made in one branch and integrate them into another branch. This is typically used to combine changes made by multiple people working on different branches, or to incorporate changes made in a development branch into a stable release branch.

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], switch to dev branch ( Make sure your commit message will reflect as "Added new feature"). [Hint use your knowledge of creating branches and Git commit command]

  • version01.txt should reflect at local repo first followed by Remote repo for review. [Hint use your knowledge of Git push and git pull commands here]

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

  • Commit this with the message “ Added feature2 in development branch”

  • 2nd line>> This is gadbad code

  • Commit this with message “ Added feature3 in development branch

  • 3rd line>> This feature will gadbad everything from now.

  • Commit with message “ Added feature4 in development branch

Restore the file to a previous version where the content should be “This is the bug fix in the development branch” [Hint use git revert or reset according to your knowledge]

Task 2:

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

  • add some changes to dev branch and merge that branch in master

  • as a practice try git rebase too, see what difference you get.

    Git Merge

    Git Rebase

Click here to check Github Repository.

Thank you for reading! 🍁

Nidhi