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

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

Git Branching

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

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.

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 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.

Refer to this article for a better understanding of Git Rebase and Merge Read here

Task 1: Question: How can you add a text file called version01.txt inside the Devops/Git/ directory with specific content, create a new branch from master, switch to the new branch, add commits to the new branch, and restore the file to a previous version?

Answer:

  1. Create a new branch called "dev" from master:git checkout -b dev
  2. Add a text file called version01.txt inside the Devops/Git/ directory with the content "This is first feature of our application":echo "This is first feature of our application" > Devops/Git/version01.txt
  3. Commit the changes with the message "Added new feature":git add Devops/Git/version01.txt git commit -m "Added new feature"
  4. Push the changes to the remote repository:git push origin dev
  5. Add new commits to the dev branch as described:echo "This is the bug fix in development branch" >> Devops/Git/version01.txt git add Devops/Git/version01.txt git commit -m "Added feature2 in development branch" echo "This is gadbad code" >> Devops/Git/version01.txt git add Devops/Git/version01.txt git commit -m "Added feature3 in development branch" echo "This feature will gadbad everything from now." >> Devops/Git/version01.txt git add Devops/Git/version01.txt git commit -m "Added feature4 in development branch"
  6. Restore the file to a previous version where the content is "This is the bug fix in development branch":git log --oneline # Find the commit hash of the previous version git checkout <commit-hash> -- Devops/Git/version01.txt git add Devops/Git/version01.txt git commit -m "Restored file to previous version"

Task 2: Question: How can you demonstrate the concept of branches with 2 or more branches, add changes to the dev branch, merge the dev branch into master, and practice git rebase?

Answer:

  1. Create two branches, branch1 and branch2:git branch branch1 git branch branch2
  2. Switch to the dev branch and make changes to files:git checkout dev # Make changes to files git add . git commit -m "Made changes in dev branch"
  3. Merge the dev branch into the master branch:git checkout master git merge dev
  4. Practice git rebase:git checkout dev # Make more changes to files git add . git commit -m "Made more changes in dev branch" git checkout master git rebase dev

These steps demonstrate how to effectively use branches, commits, merges, and rebases in Git to manage project development.

Koenraad Block

Founder @ Bridge2IT +32 471 26 11 22 | Business Analyst @ Carrefour Finance

11 个月

Your contributions to the field of DevOps are invaluable. Keep up the great work! ????

回复
Utsav Bayaskar

DevOps Engineer at Capgemini

1 年

Learning Advanced Git & GitHub !! hashtag #happylearning !!

回复

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

Utsav Bayaskar的更多文章

社区洞察

其他会员也浏览了