CodeBlanks Logo Icon CodeBlanks

stash branch

Learn to pop a stash onto a new branch with stash branch.

Create a branch from a stash entry

git stash branch creates a new branch based on a selected stash entry and applies the saved changes to that branch. This allows you to continue working in a separate workspace. The command starts the new branch from the commit where the stash entry was created.

git stash branch feature-work

git stash branch feature-work stash@{1}

The second example uses a specific stash entry. After a successful application, the used stash entry is removed from the list.

Why use stash branch?

If a stash entry was created from an older commit, applying its changes on the current branch may cause conflicts. git stash branch can reduce the chance of such conflicts by applying the changes in an environment close to their original commit.

git stash branch bugfix-work stash@{0}

This approach is especially useful when resuming work that has been stashed for a long time. A conflict-free result is not guaranteed, so changes should still be checked.

Practice Create a branch from a stash

Add git stash list and git stash branch review-work stash@{0} to the commands array in that order. Then print the commands on separate lines.

Starter code

terminal
const commands = [
    // Stash ve dal komutlarını ekle
];

// Komutları yazdır

Sample solution

terminal
let commands = [
    "git stash list",
    "git stash branch review-work stash@{0}"
];

console.log(commands.join("\n"));

Expected output

git stash list
git stash branch review-work stash@{0}

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which command creates a new branch from a specific stash entry?

  • git merge stash@{1}
  • git branch stash@{1}
  • git stash branch feature-work stash@{1} Correct answer
  • git switch stash@{1}

Explanation: With <code>git stash branch</code>, the new branch name comes first, followed optionally by the stash reference.

2 Create a new working branch

Question
git stash branch ____ stash@{0}
Answer
git stash branch bugfix-work stash@{0}

Explanation: The first argument of the command is the name of the branch to create.

3 Stash branch components

Term Meaning
stash branch Creates a branch from a stash
feature-work Name of the new branch
stash@{1} A specific stash entry
Orijinal commit The stash starting point

All lessons in Advanced