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

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

·

2 min read

Git Stash

  1. In git stash command is used to temporarily save changes that you've made to your working directory but are not ready to commit.

  2. This can be useful when you need to switch to a different branch, pull changes from a remote repository, or perform other operations that might interfere with your current changes.

  3. Stashing allows you to store your changes in a safe place, revert your working directory to a clean state, and later reapply those changes.

  1. Stash changes:
  • git stash save "Your stash message"
  1. Do other tasks (switch branches)

  2. Retrieve stashed changes:

  • git stash apply
  1. Optionally, remove the stash:
  • git stash drop

This allows you to switch between tasks without committing incomplete changes.

Cherry-pick

  1. In Git, 'cherry-pick' is a command used to apply a specific commit from one branch to another.

  2. It allows you to pick and choose individual commits and apply them to another branch, providing a way to selectively transfer changes between branches.

Let's say you have a branch called 'manasa-branch' with a commit you want to apply to your 'main' branch.

  1. Identify the commit you want to cherry-pick use the below command :

    • git log
  2. Switch to the branch where you want to apply the commit:

    • git checkout main
  3. Cherry-pick the commit:

    • git cherry-pick <commit-hash>
  4. Resolve any conflicts: If there are conflicts during the cherry-pick process, you need to resolve them manually. Git will mark the conflicted files, and you can use git status to see which files need attention.

  5. Complete the cherry-pick:

    After resolving conflicts, add the changes and complete the cherry-pick.

    • git add .

    • git cherry-pick --continue

  6. you can abort the cherry-pick if needed:

    • git cherry-pick --abort

THANK YOU FOR READING!

Do follow me on LinkedIn for further blogs.

linkedin.com/in/manasa-j-03b633238