Devops(Day - 11) Advance Git & GitHub for DevOps Engineers-Part 2

Devops(Day - 11) 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 Git command that allows you to temporarily save changes that are not yet ready to be committed. This is useful when you need to switch to a different branch or work on a different task, but don't want to commit incomplete changes to the current branch.

When you run git stash, Git takes all the changes that you have made to tracked files and saves them in a "stash" - a stack of temporary commits. The changes are removed from your working directory, leaving you with a clean slate to work on.

Cherry-pick:

git cherry-pick is a Git command that allows you to apply a specific commit or a range of commits from one branch to another. It is useful when you want to selectively apply changes from one branch to another, without having to merge the entire branch.

To use git cherry-pick, you first need to identify the commit or commits that you want to apply. You can do this by looking at the commit history of the source branch and identifying the commit hashes of the desired changes.

Once you have identified the commit or commits, you can switch to the target branch and run the git cherry-pick command followed by the commit hash(es). Git will then apply the changes from the specified commit(s) to the current branch.

If there are any conflicts between the changes being cherry-picked and the current state of the target branch, Git will prompt you to resolve the conflicts manually.

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.

git add command is used to add the resolved files.

Task-01

Atlassian Announces Stash 2.0 with Several Enterprise Offerings ...

Create a new branch and make some changes to it.

Use git stash to save the changes without committing them

Switch to a different branch, make some changes and commit them.

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

Now See all commit:

Here, You can see new commits at the top after a stash

Task-02

Branching and Merging in GIT

  • In version01.txt of development, the branch adds 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 alteration”

    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).

Make sure you are on the development branch:

Task-03

  • In Dev branch Cherry pick Commit “Added feature2.2 in production branch” and added below lines in it:

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

  • Line4>>Added few more changes to make it more optimized.

  • Commit: Optimized the feature

Thank you for reading my article.

Have a nice day.