Git Branching:-
git branch
git branch -d <branch> Create a new branch
git branch -D <branch> Delete the specified branch
git branch -m <branch> Force delete the specified branch
git checkout <branchname> switch branch
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:-
Git revert
is similar to git reset
, but the approach is slightly different. Instead of removing all the commits in its way, the revert ONLY undoes a single commit by taking you back to the staged files before the commit.
So, instead of removing a commit, git revert
inverts the changes introduced by the original commit by creating a new commit with the underlying inverse content. This is a safe way to revoke a commit because it prevents you from losing your history.
It is important to know that the revert will have no effect unless the commit hash or reference is specified.
Two commonly used tools that git users will encounter are those of 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.
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.
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 actually called “merge,” even though both procedures do essentially the same thing.
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
, switch to dev
branch ( Make sure your commit message will reflect as "Added new feature").
mkdir -p Devops/git
cat >version01.txt
“This is first feature of our application”
git checkout -b dev
git add .
git commit -m "this is my first feature"
-
version01.txt should reflect at local repo first followed by Remote repo for review.
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 lines1st line>> This is the bug fix in development branch
cat >>version01.txt 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”
Task two will be continued in next blog........
Thanks for reading.....