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

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

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.

  • 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 command shows the list of stashed changes.

  • 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 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 command shows the files that have conflicts, git diff command shows the difference between the conflicting versions and git add command is used to add the resolved files.

Task-01

  • Create a new branch and make some changes to it already created a new branch called feature_branch lets enter in to it and make some changes
git checkout feature_branch

echo "jus now we have enter into Day-11 task" >> demo.txt
git add demo.txt

  • Use git stash to save the changes without committing them:
git stash

  • Switch to a different branch, make some changes, and commit them:
git checkout -b new_branch

echo "this is new file" > new_demo.txt
cat new_demo.txt
git add new_demo.txt
git commit -m "added new demo file"

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

git commit -m "added demo.txt file from the feature_branch"

Task-02

Inversion01.txtof the development branch, add the specified lines after the existing content:

  • Now , change the branch to dev to make the commits as given in the task
git checkout dev

echo "After bug fixing, this is the new feature with minor alteration" >> version01.txt
git add version01.txt
git commit -m "Added feature2.1 in development branch"

echo "This is the advancement of the previous feature" >> version01.txt
git add version01.txt
git commit -m "Added feature2.2 in development branch"

echo "Feature 2 is completed and ready for release" >> version01.txt
git add version01.txt

git log --oneline

  • Reflect these commit messages in the Production branch using rebase:
git checkout -b production

git rebase dev && git log --oneline

Task-03

  • Cherry pick the commit "Added feature2.2 in development branch" into the Production branch:
git cherry-pick <commit_hash_of_feature2.2>

  • Resolving the error by add the specified lines after "This is the advancement of the previous feature"
echo "Added few more changes to make it more optimized." >> version01.txt
git add version01.txt
git commit -m "Optimized the feature"

cat version01.txt


Happy Learning

Thanks For Reading! :)

-DevOpsParthu💝