Skip to main content

Command Palette

Search for a command to run...

🔄️Day 11 - Advance Git & GitHub for DevOps Engineers: Part-II

Updated
2 min read
🔄️Day 11 - Advance Git & GitHub for DevOps Engineers: Part-II
V

👋 Hello there! I'm Vivek, a DevOps enthusiast with a keen interest in streamlining software delivery. I hold a Master's degree in Computer Applications and have a solid foundation in key technologies such as Linux, Git, Docker, Kubernetes, and AWS.

💻 My passion lies in automation, ensuring efficient and seamless processes throughout the software development lifecycle. I thrive on creating robust CI/CD pipelines that empower teams to deliver high-quality software with confidence.

🚀 Beyond the code, I enjoy the ever-evolving world of DevOps and the challenges it brings. Join me on this journey as I explore new ways to enhance software delivery and foster a culture of continuous improvement.

Let's connect, collaborate, and make the world of DevOps even more exciting together

🌱Git Stash

Git stash is a command that allows you to temporarily save changes you have made in your working directory, without committing them. This is useful when you need to switch to a different branch to work on something else, but you don't want to commit the changes you've made in your current branch yet.

Example of how git stash works:

Suppose you're working on a branch let's say feature in your Git repository and you've made changes to your files but you're not ready to commit them because you want to switch to another branch to fix a bug.

  1. To stash your changes

     git stash
    

    This will stash your changes, and gets your working directory clean.

  2. You can switch to another branch now using git checkout:

     git checkout <Next_Branch_name>
    
  3. After working on the other branch, you then decided to come back to your previous changes. To retrieve your changes from the stash, you can use:

     git stash pop
    

    This is a basic example of how git stash can be used to temporarily store changes in Git. It's very flexible when you need to switch work.

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

Example:

  1. Create 2 Branches

      git checkout -b devops
      # Make changes and commits on devops branch
      git commit -m "Commit 1 on devops"
      git commit -m "Commit 2 on devops"
    
      git checkout -b feature
      # Make changes and commits on feature branch
      git commit -m "Commit 1 on feature"
      git commit -m "Commit 2 on feature"
    
  2. Now, apply "Commit 2 of devops branch" to feature branch

    find the commit hash code of "Commit 2 on devops":

     git log --oneline 
     #log command show all the commits with hash ID
    
  3. Switch to feature branch now:

      git checkout feature
    
  4. Cherry-pick the commit from devops branch:

      git cherry-pick <commit_hash_ID>
    
  5. Resolve conflicts You'll need to manually resolve these conflicts, stage the changes, and continue the cherry-pick with git cherry-pick --continue.

  6. Once conflicts are resolved (if any), the commit from devops will be cherry-picked onto feature.

🌱Conclusion

In summary, git stash is for temporarily storing changes at backstage, while git cherry-pick is for selectively applying specific commits to another branch. Both commands are valuable tools in managing your Git workflow efficiently.

Happy Learning😊

More from this blog

Vivek's Blog

37 posts