Day 10 : Advance Git & GitHub

Day 10 : Advance Git & GitHub

Git Branching

Git branching is the practice of creating multiple versions of a codebase, allowing multiple developers to work on different features or changes without interfering with each other's work. Branching creates a separate timeline of changes from the main codebase, enabling developers to experiment and test new ideas. Once a branch is completed, it can be merged back into the main codebase. Git's branching system makes collaboration on large projects more efficient and organized.

Git Revert and Reset

Git revert and reset are two commands used to undo changes in a Git repository.

Git revert creates a new commit that undoes the changes made in a previous commit. This allows developers to keep a record of the undone changes, and is useful when changes have already been pushed to a remote repository. Reverting a commit doesn't delete it, but rather creates a new commit that reverses the changes made in the original commit.

Git reset, on the other hand, allows developers to undo changes by resetting the current branch to a specific commit. This can be useful when changes haven't been pushed to a remote repository yet. Resetting a branch erases all changes made after the specified commit, effectively "rewinding" the repository to that point. This can be done in different modes depending on the option used.

Both Git revert and reset can be powerful tools, but it's important to use them with care to avoid accidentally losing important changes.

Git Rebase and Merge

What Is Git Rebase?

Git rebase is a command used to integrate changes from one branch onto another by applying each individual commit of the source branch onto the target branch. This can result in a cleaner and more linear commit history.

What Is Git Merge?

Git merge is a command used to combine changes from different branches into a single branch. It creates a new commit that includes the changes from the merged branches. Merge is often used for bringing feature branches into a main branch, like master.

Task 1:

  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, switch to dev branch

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 development branch

Restore the file to a previous version where the content should be “This is the bug fix in 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

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