Day 10 Task: Advance Git & GitHub for DevOps Engineers.

Day 10 Task: Advance Git & GitHub for DevOps Engineers.

1.What is Git Branching?

==>Git branching is a powerful feature that allows you to work on different versions of your project simultaneously without affecting the main codebase. This is useful for developing new features, fixing bugs, and collaborating with other team members.

To create a new branch, use the git branch command:

git branch new-branch-name

To switch to a different branch, use the git checkout command:

git checkout branch-name

To see a list of all your branches, use the git branch command without any arguments:

git branch

To merge two branches together, use the git merge command:

git merge branch-name

To delete a branch, use the git branch -d command:

git branch -d branch-name

Here are some common Git branching workflows:

Feature branches: When you're working on a new feature, it's a good idea to create a new branch to isolate your changes from the main codebase. This way, you can experiment and make changes without affecting the production version of your project. Once you're finished with the feature, you can merge it into the main branch.

Bugfix branches: When you need to fix a bug, you should also create a new branch to isolate your changes. This way, you can make sure that your fix doesn't introduce any new bugs. Once you're fixed the bug, you can merge it into the main branch.

Release branches: When you're ready to release a new version of your project, you can create a release branch to prepare the release. This branch should be used to make any final changes and test the release. Once you're happy with the release, you can merge it into the main branch and deploy it to production.

Git branching is a powerful tool that can help you to manage your code more effectively.

2.What is Git Revert and Reset ?

==>git revert and git reset are both commands that can be used to undo changes in Git. However, they have different purposes and work in different ways.

git revert creates a new commit that reverses the changes made by a previous commit. This is a safe way to undo changes, as it does not alter the existing commit history.

git reset moves the HEAD pointer back to a previous commit, effectively discarding any commits that were made after that point. This can be useful for undoing uncommitted changes or for removing commits that contain mistakes. However, it is important to note that git reset is a destructive operation and can alter the existing commit history.

  • Which command should you use?

If you want to undo changes that have been committed to the repository, you should use git revert. This is a safe way to undo changes, as it does not alter the existing commit history.

If you want to undo uncommitted changes or remove commits that contain mistakes, you can use git reset. However, it is important to note that git reset is a destructive operation and can alter the existing commit history.

3.What Is Git Rebase?

==>Git rebase is a command that allows you to rewrite the history of your commits. It does this by replaying your commits on top of a different base commit. This can be useful for a variety of reasons, such as:

Cleaning up your commit history by squashing or splitting commits

Moving commits from one branch to another

Integrating changes from upstream without creating merge commits

To use git rebase, you first need to identify the base commit that you want to rebase your changes on. This can be done using the git log command. Once you have identified the base commit, you can use the git rebase command to replay your commits on top of it.

For example, to rebase your last three commits on top of the current HEAD commit, you would use the following command:

git rebase HEAD~3

This would create three new commits, each of which would contain the changes from the original commit, but applied on top of the current HEAD commit.

Git rebase can be a powerful tool, but it's important to use it with caution. Rebasing can rewrite the history of your commits, which can make it difficult to track down and fix bugs.

4.What Is Git Merge?

==> Git merge is a command that allows you to combine two or more branches of a Git repository into a single branch. This is useful for integrating changes from different team members or for bringing in changes from upstream.

To merge two branches, you first need to checkout the branch that you want to merge into. Then, you can use the git merge command to merge the other branch into it.

For example, to merge the feature branch into the main branch, you would use the following command:

git checkout main

git merge feature

This would create a new commit on the main branch that combines the changes from the feature branch.

If there are any conflicts between the two branches, Git will prompt you to resolve them. Once you have resolved all of the conflicts, you can commit the merge.

Git Command

===================================================

Task 1: Adding a Text File and Managing Commits

?? Start by branching off from the main tree (master) and create a new branch called 'dev' using this command:

git checkout -b dev

?? Now, in the 'Devops/Git/' directory, plant a new file named version01.txt with the words "This is the first feature of our application" written inside.

?? Commit your changes to this new branch with a note saying "Added new feature" using this command: git add Devops/Git/version01.txt followed by git commit -m "Added new feature".

?? Send your changes to the remote garden for everyone to see with:

git push origin dev

?? Add more thoughts to version01.txt as described in your task:

Line 1: "This is the bug fix in development branch"

Line 2: "This is gadbad code"

Line 3: "This feature will gadbad everything from now."

?? Record each of these thoughts with their respective messages:

git commit -am "Added feature2 in development branch"

git commit -am "Added feature3 in development branch"

git commit -am "Added feature4 in development branch"

To Restore the File:

?? If you want to turn back time and get back to a previous version of the file, you have two options:

Use git reset (this erases the last three changes):

git reset HEAD~3 git push -f origin dev

Use git revert (this writes new notes to cancel out the changes):

git revert HEAD~3..HEAD git push origin dev

Task 2: Demonstrating Branches, Merging, and Rebasing

Grow two or more new branches:

git checkout -b branch1

git checkout -b branch2

Make some waves in the 'dev' branch and write them down. Combine 'dev' with 'master' by using this magical spell:

git checkout master

git merge dev

Optionally, experiment with rebasing by running:

git checkout branch1

git rebase dev

Observe the differences in the commit history and how it affects branch structure.

Keep branching, merging, and rebasing! ??


#DevOps #Git #GitHub #AdvancedGit #DevOpsEngineers #VersionControl ?????? #tws Shubham Londhe

要查看或添加评论,请登录

Prakash Bohara的更多文章

社区洞察

其他会员也浏览了