Day 10 Task: Advance Git & GitHub for DevOps Engineers.
Leveling Up: Advanced Techniques and Best Practices on GitHub
🔶 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 revert <commit-id>
🔶 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.
git rebase <branch name>
🔶 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 called “merge,” even though both procedures do essentially the same thing.
git merge <name of the branch to be merged> <branch name from where to merged>.
🔶 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 the dev
branch ( Make sure your commit message will reflect as "Added new feature"). [Hint use your knowledge of creating branches and Git commit command]
A committed message with "Added new feature".
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]
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
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 a screenshot.
add some changes to
dev
branch and merge that branch inmaster
as a practice try git rebase too, and see what difference you get.
The following are the most used Git rebase commands:git rebase master: The command “git rebase master” can be used to make all modifications found in your master branch part of your current branch.
git rebase –continue: When we are rebasing the branches we will face some conflicts and issues then we need to resolve the issue. After resolving the issue we again continue the rebasing processes for that we use “git rebase –continue”.
git rebase –abort: “Git rebase –abort” command cancels a rebase that is currently underway and restores the branch to its initial state.
git rebase –skip: When rebasing the branches we might face some unresolved conflicts to skip the particular encounters we will use “git rebase –skip”. Skipping the commit is not good practice it will damage your codebase.
git rebase -I HEAD~3: With the help of this command, you can interactively rebase the most recent three commits onto the active branch. You can choose which commits to rebase, alter commit messages, and squash or divide commits in the interactive editor that is opened.
Stay in the loop with my latest insights and articles on cloud ☁️ and DevOps ♾️ by following me on Hashnode, LinkedIn (https://www.linkedin.com/in/chandreshpatle28/), and GitHub (https://github.com/Chandreshpatle28).
Thank you for reading! Your support means the world to me. Let's keep learning, growing, and making a positive impact in the tech world together.