day10 of #90daysofdevops

Advance Git & GitHub for DevOps Engineers.

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 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 previous commits.

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 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.

Refer to this article for a better understanding of Git Rebase and Merge Read here

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]

image

image

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

    • To move changes from the local repo to the remote, we push. To bring them to the local from the remote, we pull.
\-- A "pull request" is you requesting the target repository to please grab your changes. A "push request" would be the target repository requesting you to push your changes

Add a new commit in dev branch after adding the 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 the development branch

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

  • 2nd line>> This is gadbad code

  • Commit this with the message “ Added feature3 in the development branch

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

  • Commit with the message “ Added feature4 in the development branch

    image

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]

image

-- > here are three commands with similar names: git reset, git restore and git revert. git-revert is about making a new commit that reverts the changes made by other commits. git-restore is about restoring files in the working tree from either the index or another commit. This command does not update your branch.

  • git revert should be used to undo changes on a public branch, and git reset should be reserved for undoing changes on a private branch. You can also think of git revert as a tool for undoing committed changes, while git reset HEAD is for undoing uncommitted changes

image

image

image

image

Task 2:

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

    image

image

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

    image

  • as a practice try git rebase too.

    • In Git, rebase is an alternative method to merge for integrating changes from one branch into another. The basic difference between merge and rebase is that merge creates a new commit that has both branches as its parent, while rebase takes the commits from one branch and replays them on top of another
![image](https://user-images.githubusercontent.com/89054489/211804158-a51ebd87-1708-43ce-94a5-b02a4794684e.png align="left")

image

image

That's it for Today. Thanks for your time.

Please share your valuable feedback by liking 👍, sharing🤝 and commenting.

See you tomorrow, with another blog.

For more such content please follow me here on hashcode.

#day10 #90DaysOfDevops #git #github #DevOps

Did you find this article valuable?

Support Nagacharan by becoming a sponsor. Any amount is appreciated!