Git Branching:
Git branching is a powerful feature of the Git version control system that allows you to work on multiple versions of your code simultaneously. A branch is a copy of your code that you can modify independently of other branches. This allows you to experiment with new features, fix bugs, or work on different aspects of your project without affecting the main branch.
Git Revert and Reset:
Git revert creates a new commit that undoes the changes made in a previous commit. This is useful when you want to keep a record of the original changes, but also want to undo them. The revert commit contains information about the commit being reverted and the changes made to undo it.
Git reset, on the other hand, moves the HEAD pointer and resets the staging area to a specific commit. This is useful when you want to completely remove changes made after a certain point in time. Git reset has three modes: soft, mixed, and hard, each of which resets the repository to a different state.
Git Rebase and Merge:
Git merge creates a new commit that combines the changes from two or more branches. This is useful when you want to merge changes from a feature branch into a main branch. The merge commit contains information about the commits being merged and the changes made to combine them.
Git rebases, on the other hand, moves the entire feature branch to begin on the tip of the main branch, effectively replaying all of the commits from the feature branch on top of the main branch. This is useful when you want to maintain a linear history or when you want to incorporate changes from a main branch into a feature branch before merging.
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
Step-1
Clone the Repository to your local system:
git clone <URL>
Step-2
Make sure you are in Main Branch, Create a branch name Dev
git branch <branch name>
git checkout <branch name>
Step-3
Create a file name version01.txt & add content to it “This is the first feature of our application”.
Step-4
Now add it and commit it with the message "Added new feature"
git commit -m < enter message 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
In this Process just edit the file, add it and commit every time with a new comment and can verify with Git log:
git log
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 in master
As a practice try git rebase too and see what difference you get.
Here at First, I create two new branches named Dev-1 & Dev-2 and switch it to Dev-2:
git branch
Firstly see what content you have in the Master/main branch and then add some content in a file in Dev-Branch and try to merge it with the Main/Master branch:
git checkout < master branch >
As you can see, I switch to the main branch and we can see there is no file name Version01.txt because we create it in Dev-Branch, now switch it to Dev-Branch and add some content to the file and try to merge it with the main.
Now try to merge it into Main Branch and verify it with ll command to see the Version01.txt file.
git merge <branch name>
Now verify it with the command 'ls' to see the same content of Dev-Branch in the main branch:
ls
You can see we have the same file Version01.txt present in our main branch.
Git Rebase:
Here is What I have done, create a new branch named branch1 from our branch Sub and create a file filex, then add it and commit otherwise it will reflect in all sub-branch and master too then switch into sub-branch and try to rebase it using the command.
git rebase <branch name>
\======================THANKYOU==========================