Day 13 Task: Advance Git & GitHub for DevOps Engineers
Mastering Advanced Git and GitHub Techniques
Git Branching
Branches are a core concept in Git that allow you to isolate development work without affecting other parts of your 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 let you develop features, fix bugs, or safely experiment with new ideas in a contained area of your repository.
Git Revert and Reset
Git reset and git revert are two commonly used commands that allow you to remove or edit changes you’ve made in the code in previous commits. Both commands can be very useful in different scenarios.
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 commit history is modified once the action is complete. Git rebase helps keep a clean project history.
What Is Git Merge?
Git merge is a command that allows developers to merge Git branches while keeping the logs of commits on branches intact. Even though merging and rebasing do similar things, they handle commit logs differently.
Tasks
- Create a Branch and Add a Feature:
Add a text file called version01.txt
inside the Devops/Git/
directory with “This is the first feature of our application” written inside.
touch version01.txt
echo "This is the first feature of out application" > version01.txt
Create a new branch from master
.
git checkout -b dev
Commit your changes with a message reflecting the added feature.
git add version01.txt
git -m "Added: First feature of app"
- Push Changes to GitHub:
Push your local commits to the repository on GitHub.
git push origin <branch name>
git push origin dev
- Add More Features with Separate Commits:
Update version01.txt
with the following lines, committing after each change:
echo "This is the bug fix in development branch" >> Devops/Git/version01.txt
git commit -am "Added feature2 in development branch"
2nd line: This is gadbad code
echo "This is gadbad code" >> Devops/Git/version01.txt
git commit -am "Added feature3 in development branch"
3rd line: This feature will gadbad everything from now
echo "This feature will gadbad everything from now" >> Devops/Git/version01.txt
git commit -am "Added feature4 in development branch"
Restore the File to a Previous Version:
git revert <commit-id>
Task 2: Working with Branches
Demonstrate Branches:
Create 2 or more branches and take screenshots to show the branch structure.
git checkout -b staging
git checkout -b QA
Merge Changes into Master:
- Make some changes to the
dev
branch and merge it intomaster
.
Before doing merge command, make sure you are in the master or main branch we need to move our latest chance over there.
git checkout main or master
Performing merge command inside the master or main branch
git merge dev
Practice Rebase:
Try rebasing and observe the differences.
Doing changes in main brach for rebasing first
Added version3.txt in the main branch:
Added version4.txt in the dev branch:
git switch dev
git switch main
git rebase dev
After doing rebase we can observe that all the changes in the branches has linear or in the sequence. First we made changes in dev and the main branch rebase command sequenced all the changes.
Follw for more update:)