Advance Git & GitHub for DevOps Engineers

Advance Git & GitHub for DevOps Engineers

Git Stash:

Stash is temporary storage that is used to store our code for some amount of time until we finish the other work. It cleans our workspace and can work on other code.

Stashing is useful when you want to switch to a different branch, but you are not yet ready to commit your current changes. Stashing your changes allows you to switch to another branch and come back to your changes later.

Git Stash command creates a new stash entry that includes the changes in your working directory, but does not include untracked files. When you're ready to continue working on the changes, you can use the git stash apply command to restore the changes to your working directory.

You can also use other Git Stash commands, such as git stash list and git stash drop, to manage your stash entries.

Cherry-pick

In Git version control system, Cherry-pick is a feature that allows developers to apply a specific commit from one branch to another.

Cherry-pick is useful when you want to incorporate a single commit from one branch into another without merging the entire branch. This can be useful in a variety of situations, such as when a bug fix is needed in a release branch but not in the main development branch, or when a feature branch has been created for a specific feature but only one commit from that branch is needed in the main branch.

To use cherry-pick, you first identify the commit you want to apply to another branch. Then, you switch to the target branch and use the git cherry-pick command followed by the commit hash of the desired commit. Git will then apply the changes from that commit to the current branch.

It's worth noting that cherry-picking a commit does not bring along the entire history of the branch that the commit was originally on, so you should only use cherry-pick for isolated commits, not as a substitute for merging branches.

Task-01

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

  • Used git stash to save the changes without committing them

  • Switched to a different branch, make some changes and commit them

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

    • Task-02

    • In version01.txt of development branch add 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

    • -- After bug fixing, this is the new feature with minor alteration”

      Commit this with message “ Added feature2.1 in development branch

      • This is the advancement of previous feature

        Commit this with message “ Added feature2.2 in development branch

  • 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