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

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

Git, the version control system, empowers developers worldwide to collaborate seamlessly and manage their projects efficiently. Among its myriad features, mastering Git branching, reverting, resetting, rebase, and merge is crucial for maintaining a clean and organized codebase. Let's delve into these essential aspects and unlock the full potential of Git.

Git Branching:

  • Branches: Think of branches as parallel universes where you can work on features or fixes without affecting the main codebase.

  • Creating Branches: Use git branch <branch-name> to create a new branch and git checkout <branch-name> to switch to it.

  • Merging Branches: After completing your changes, merge the branch back into the main codebase using git merge <branch-name>.

  • Branch Management: Keep your repository clean by regularly deleting merged branches with git branch -d <branch-name>.

Git Revert and Reset:

  • Revert: Undo specific commits while preserving the commit history using git revert <commit-id>.

  • Reset: Roll back changes entirely with git reset <commit-id>. Use --soft, --mixed, or --hard flags for different reset modes.

  • Caution: Exercise caution with reset as it can alter history and potentially lose commits. Only use it for local changes.

FeatureGit ResetGit Revert
ActionResets current branch to a specified commitReverts specified commits by creating new ones
Commit HistoryRewrites commit historyPreserves commit history
ImpactHard reset: discards commits permanentlySoft reset: retains commits in reflog
CollaborationCan cause conflicts in shared repositoriesSafer for shared repositories
UsageUseful for local changes and branch cleanupRecommended for reverting public changes

Git Rebase and Merge:

  • Rebase: Rewrite commit history to maintain a linear project history. Use git rebase [base] [branch] to rebase the current branch onto the base branch.

  • Interactive Rebase: Fine-tune commits interactively with git rebase -i [base].

  • Merge: Combine changes from different branches into one. Use git merge <branch> to merge the specified branch into the current one.

FeatureGit RebaseGit Merge
OperationReapplies commits on top of anotherIntegrates changes from different branches
HistoryLinearizes commit historyPreserves branch history
ClarityResults in a cleaner, linear historyMaintains original context of development
ConflictsResolved per commitResolved at merge com

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"). [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 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 screenshot.

add some changes to fruitsbranch and merge that branch in main

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

Created fruits branch using command git checkout -b fruits

Created games branch using command git checkout -b games

Use command git branch to list all the git branches (* is current branch)

Use command git merge fruits to merge fruits branch in main branch

In conclusion, Git's versatility lies in its ability to adapt to various workflows seamlessly. By mastering branching, reverting, resetting, rebase, and merge, you equip yourself with the tools needed to navigate complex development scenarios with ease. Embrace Git's power, experiment fearlessly, and let it propel your projects to new heights!

Happy coding!