Day 11 - Advance Git & GitHub for DevOps Engineers: Part-2 ๐Ÿš€

Day 11 - Advance Git & GitHub for DevOps Engineers: Part-2 ๐Ÿš€

ยท

2 min read

Unveiling Git Stash, Cherry-Pick, and Conflict Resolution ๐ŸŒŸ

Git Stash: Save Now, Apply Later! ๐Ÿ“ฆ๐Ÿ’ผ

Ever needed to switch branches without committing your changes? Enter Git Stash! It's like a coding pause button. Use git stash to save your work, and git stash pop to bring it back when you're ready. Easy peasy! ๐ŸŽ‰

Cherry-Pick: Selective Commit Magic! ๐Ÿ’โœจ

Git Cherry Pick: All Developers Should Know | by Colton | The Crazy Coder |  Medium

Git Cherry-Pick lets you choose specific commits from one branch and apply them elsewhere. It's like cherry-picking the best commits for your masterpiece. ๐ŸŽจ๐Ÿ”—

Resolving Conflicts: The Peacekeeper Mode! ๐Ÿค๐Ÿšง

Conflicts happen, but fear not! git status shows conflicts, git diff reveals differences, and git add brings resolution. Conflict? Resolved! โœ…๐Ÿ’ช

Hands-On Tasks: Git in Action! ๐Ÿ› ๏ธ๐Ÿ’ป

Task 1: Stash and Pop, Like a Pro!

  1. Create a new branch and make changes:

     git checkout -b feature-branch
     # Make changes to your files
    
  2. Use git stash to save changes:

     git stash
    
  3. Switch branches, make changes, and commit:

     git checkout main
     # Make changes to your files and commit
    
  4. Use git stash pop to bring back saved changes:

     git checkout feature-branch
     git stash pop
    

Task 2: Feature Evolution with Rebase!

  1. In version01.txt, add new lines and commit:

     # Assuming version01.txt is already present
     git add version01.txt
     git commit -m "Add new lines in version01.txt"
    
  2. Reflect commit messages in the Production branch using rebase:

     git checkout production
     git pull origin production
     git rebase main
     # Resolve conflicts if any, and continue the rebase
     git rebase --continue
     # Repeat the above step if there are multiple conflicts
    

Task 3: Cherry-Pick Magic in Production!

  1. Cherry-pick a commit from Development:

     git checkout production
     git cherry-pick <commit-hash>
     # Replace <commit-hash> with the actual hash of the commit you want to cherry-pick
     # Resolve conflicts if any, and continue the cherry-pick
     git cherry-pick --continue
     # Repeat the above step if there are multiple conflicts
    
  2. Add more lines, commit with an optimization twist:

     # Make changes to your files
     git add .
     git commit -m "Add more lines with optimization"
    

Reflecting on Git Mastery! ๐ŸŒŸ๐Ÿค”

Day 11 delved into Git Stash, Cherry-Pick, and Conflict Resolution. Share your learnings, challenges! How's your Git journey evolving? Let's chat! ๐Ÿ’ฌ๐Ÿš€

Did you find this article valuable?

Support Nilkanth Mistry by becoming a sponsor. Any amount is appreciated!

ย