Day-11 of DevOps Challenge: Advanced Git & GitHub Strategies Part-2

Day-11 of DevOps Challenge: Advanced Git & GitHub Strategies Part-2

What is Git Stash

git stash is a Git command used to temporarily save changes you’ve made to your working directory. It allows you to set aside your current work so you can switch branches or work on something else, and then reapply your changes later. Here’s a concise look at the key features and common commands of git stash

Key Features

Temporary Storage: Shelves your current changes without committing them.

Context Switching: Enables you to switch branches or work on different tasks without losing your changes.

Untracked Files: Can optionally include untracked files in the stash.

Here is the used Git Stash Command List and Usage

Stash Changes:

Command: git stash

Usage: Shelves your local modifications and reverts the working directory to the latest commit.

Stash with a Message:

Command: git stash save "your message"

Usage: Saves your changes with a custom message for easier identification.

List Stashes:

Command: git stash list

Usage: Displays a list of all stashed changes with their corresponding messages and indexes.

Apply Latest Stash:

Command: git stash apply

Usage: Reapplies the latest stashed changes to your working directory without removing the stash from the list.

Apply Specific Stash:

Command: git stash apply stash@{n}

Usage: Reapplies a specific stash identified by its index (n).

Pop Latest Stash:

Command: git stash pop

Usage: Reapplies and removes the latest stashed changes from the stash list.

Pop Specific Stash:

Command: git stash pop stash@{n}

Usage: Reapplies and removes a specific stash identified by its index.

Drop Specific Stash:

Command: git stash drop stash@{n}

Usage: Removes a specific stash identified by its index without applying it.

Clear All Stashes:

Command: git stash clear

Usage: Removes all stashed changes from the stash list.

Stash Only Unstaged Changes:

Command: git stash save --keep-index

Usage: Stashes only the changes that have not been added to the index (unstaged changes), keeping the staged changes intact.

Stash Including Untracked Files:

Command: git stash save -u

Usage: Includes untracked files in the stash along with tracked changes.

Stash Including Untracked and Ignored Files:

Command: git stash save -a

Usage: Includes both untracked and ignored files in the stash.

Show Stash Details:

Command: git stash show stash@{n}

Usage: Displays the changes in a specific stash identified by its index.

Show Stash Diff:

Command: git stash show -p stash@{n}

Usage: Shows a detailed diff of what is included in a specific stash identified by its index.

Create a Branch from Stash:

Command: git stash branch branch-name stash@{n}

Usage: Creates and checks out a new branch starting from the commit at which the stash was created, then applies the stashed changes to it.

What is Cherry-pick

git cherry-pick is a Git command that allows you to apply the changes introduced by one or more existing commits from another branch to your current branch. This command is particularly useful when you want to incorporate specific changes from one branch into another without merging the entire branch.

Key Features of Git Cherry-pick

Selective Commit Application: You can pick specific commits to apply, without affecting the rest of the commit history.

Flexibility: Allows for incorporating bug fixes or features from other branches individually.

Conflict Resolution: Handles conflicts that may arise when applying changes, similar to a merge conflict.

Here is the used Git Stash Command List and Usage

Cherry-pick a Single Commit:

Command: git cherry-pick <commit-hash>

Usage: Applies the changes from the specified commit to the current branch.

Cherry-pick Multiple Commits:

Command: git cherry-pick <commit-hash1> <commit-hash2>

Usage: Applies the changes from multiple specified commits to the current branch.

Cherry-pick a Range of Commits:

Command: git cherry-pick <start-commit-hash>^..<end-commit-hash>

Usage: Applies the changes from a range of commits. The ^ symbol ensures the inclusion of the start-commit-hash.

Abort an Ongoing Cherry-pick:

Command: git cherry-pick --abort

Usage: Aborts the cherry-pick process and returns to the state before the cherry-pick.

Continue a Cherry-pick After Resolving Conflicts:

Command: git cherry-pick --continue

Usage: Continues the cherry-pick process after conflicts have been resolved.

Skip a Commit During Cherry-pick:

Command: git cherry-pick --skip

Usage: Skips the current commit during a cherry-pick process if you decide not to apply it after resolving conflicts.

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.

I have performed some tasks that might help everyone on Advanced Git & GitHub Strategies

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.

Article content
Article content
Article content
Article content
Article content

In version01.txt of development branch add below lines.

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

Article content
Article content
Article content

In Production branch Cherry pick Commit “Added feature2.2 in development 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

Article content
Article content
Article content
Article content

TrainWithShubham Shubham Londhe

To view or add a comment, sign in

More articles by Akash Rastogi

Explore content categories