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

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

#devops#git

Git Branching

Use a branch to isolate development work without affecting other branches in the repository. Each repository has one default branch and can have multiple other branches. You can merge a branch into another branch using a pull request.

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

Git Revert and git Reset:

Two commonly used tools that git users will encounter are git reset and git revert. the benefit of both of these commands is that you can use them to remove or edit changes you've made in the code in the previous commit.

Revert changes that you want to undo and added a new commit.

git revert <commit id>

commit id by : git log --online

git reset will remove history from the project.

Git Rebase and Merge:

  • what is git rebase?

Git rebase is a command that lets users integrate changes from one branch to another and the logs are modified once the action is complete. git rebase was developed to overcome merging's shortcomings, specifically regarding logs.

  • 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 working of git rebase and merge:

    Git rebase takes all the changes and compresses them into a single patch and integrates the new patch onto the target branch. then, it moves the completed work from one branch to another typically the master branch. In the process, rebase flattens the history, removing unwanted entries.

  • Git merge on the other hand, only changes the target branch and creates a commit preserving the history of the source branch

Difference:

Merge

Rebase

Merge lets you merge different Git branches.

Rebase allows you to integrate the changes from one branch into another.

Merge logs show you the complete history of commit merging.

Rebase logs are linear. As the commits are rebased, the history is altered to reflect this.

All the commits on a feature branch are combined into a single commit on the master branch.

All commits are rebased, and the same number of commits are added to the master branch.

Merge is best used when the target branch is supposed to be shared.

Rebase is best used when the target branch is private.

Merge preserves history.

Rebase rewrites history.

Task 1:

Add a text file called version01.txt inside the Devops/Git/ with “This is the 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 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 the development branch

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

Task 2:

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

  • Add some changes to dev the branch and merge that branch in master

      $ git merge master
    
  • as a practice try git rebase too, and see what difference you get.

Thank you for reading this Blog. Hope you learned something new today! If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future😊😊

I would like to connect with you at https://medium.com/@madhuripatiletc48/