Advance Git & GitHub for DevOps Engineers.
1.Git Branching
-Branch in Git is similar to the branch of a tree. Analogically, a tree branch is attached to the central part of the tree called the trunk. While branches can generate and fall off, the trunk remains compact and is the only part by which we can say the tree is alive and standing. Similarly, a branch in Git is a way to keep developing and coding a new feature or modification to the software and still not affecting the main part of the project. We can also say that branches create another line of development in the project. The primary or default branch in Git is the master branch (similar to a trunk of the tree). As soon as the repository creates, so does the main branch (or the default branch).
2.Git Revert and Reset
-git revert is used to remove the commits from the remote repository. -git revert -git reset is used when we want to unstage a file and bring our changes back to the working directory. -git reset can also be used to remove commits from the local repository. -git reset HEAD #command
3.Git Rebase and Merge
-rebase flattens the history, removing unwanted entries. -Git merge, only changes the target branch and creates a commit, preserving the history of the source branch
4.What Is Git Rebase?
- Rebasing is the process of moving or combining a sequence of commits to a new base commit.
- Rebasing is most useful and easily visualized in the context of a feature branching workflow.
5.What Is Git Merge?
- Merging is Git's way of putting a forked history back together again.
- The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch.
#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]
- mkdir devops
- cd devops
- touch version01.txt
- vim version01.txt
- “This is first feature of our application” #in vim insert i command
- cat version01.txt
- git init
- git status
- git checkout -b dev
- git commit -m "added new feature"
- git add version01.txt
- git status
- git push --all origin
-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]
-mkdir github -cd github -clone -git status -touch demo.txt -vim"added feature in development branch" -cd demo.txt -git add demo.txt -git commit -m " added feature is added" -git push --all origin
Task 2:
-Demonstrate the concept of branches with 2 or more branches with screenshot. -Git branches are commonly used when there's a new feature, bug fix, or anything else in your code you might want to track and compare to previous versions. This helps to identify and track instances where something goes wrong with a bug fix or a new feature release.
thank you!