🚀Day 11 Task: Advance Git & GitHub for DevOps Engineers: Part-2

📕Git Stash

  • git stash is like putting your code changes in a temporary box.

  • To use Git stash, you first create a new branch and make some changes to it. Then you can use the command git stash to save those changes. This will remove the changes from your working directory and record them in a new stash. You can apply these changes later. git stash list the command shows the list of stashed changes.

  • git stash helps you save your ongoing work without having to commit it, so you can switch tasks temporarily and then return to your work without any mess. You can also use git stash drop to delete a stash and git stash clear to delete all the stashes.

📕Cherry-pick

Git cherry-pick is a command that allows you to select specific commits from one branch and apply them to another. This can be useful when you want to selectively apply changes that were made in one branch to another.

To use git cherry-pick, you first create two new branches and make some commits to them. Then you use git cherry-pick <commit_hash> command to select the specific commits from one branch and apply them to the other.

📕Resolving Conflicts

Conflicts can occur when you merge or rebase branches that have diverged, and you need to manually resolve the conflicts before git can proceed with the merge/rebase.

git status the command shows the files that have conflicts, git diff The command shows the difference between the conflicting versions and git add a command is used to add the resolved files.


📝Tasks

Task-01

  1. Create a new branch and make some changes to it.

    We can use the below command to create a new branch.

     git checkout -b feature1
    
  2. Use git stash to save the changes without committing them.

     git stash save "feature1"
    
  3. Switch to a different branch, make some changes, and commit them.

     git checkout mainfeature
    

Use git stash pop to bring the changes back and apply them on top of the new commits.

git stash pop

Task-02

  • In version01.txt of the development branch add the below lines after “This is the bug fix in development branch” that you added in Day10 and reverted to this commit.

  • Line2 -> After bug fixing, this is the new feature with minor alterations”

Commit this with message “ Added feature2.1 in development branch”

  • Line3 -> This is the advancement of previous feature

Commit this with message “ Added feature2.2 in development branch”

  • Line4 -> Feature 2 is completed and ready for release

Commit this with message “ Feature2 completed”

  • All these commits messages should be reflected in Production branch too which will come out from Master branch (Hint: try rebase).
git rebase master

Task-03

  • In the Production branch Cherry pick Commit “Added feature2.2 in development branch” and added the below lines in it:

  • The line to be added after Line3>> This is the advancement of the previous feature

  • Line 4 Added a few more changes to make it more optimized.

  • Commit: Optimized the feature


🌟 Conclusion:

Congratulations! 🎉

Git is an essential tool ⚙️ for developers 👨🏻‍💻to manage their code, collaborate effectively, and maintain a detailed record of their project's development history. It's widely used across the software industry and has become a standard tool for version control and collaborative coding.

GitHub 😸 is a web-based platform where developers can collaborate, contribute, and showcase their coding skills.

We hope this blog has given you a Question/Answer 🚀💪

🔍 Did you find this blog helpful? Let us know in the comments below! 👇 And if you have any questions or need further assistance, we're here to help! 🤗

Happy Learning! 💻✨