🎁

12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
13 : 08 : 53 : 17
Join egghead, unlock knowledge.

Want more egghead? It's 58% off for a limited time only!

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock All Content for 40% Off
1×
Become a member
to unlock all features
Autoplay

    Temporarily store some work in progress because I have to jump to another branch

    Juri StrumpflohnerJuri Strumpflohner
    gitgit

    We all know this. You’re working on some new feature and you have lots of “work in progress”. Then an urgent issue comes in, you have to jump onto the master and apply a hotfix. In this lesson we will learn how to temporarily store your current changes s.t. you can switch the current branch and come back later to resume your work again.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: I am currently in my app folder branch here where I am creating a new app for the component for our application.

    Assume I have to change back to master because there is some bug that came in and we have to do a hot fix on there. In order to not lose my ongoing changes here, what I could do is either to commit a working progress commit on my future branch, which I'll then clean up later, or I can use the git stash command.

    Here I am having one file that has been modified and one that hasn't even being tracked by git. In order to capture all of them, let's just do a git add. I'll apply git stash.

    If I take a look now at my git repository, you can see that nothing has to be committed and everything is clean basically. I can now go back to master, apply my changes. Let's simply open the Readme here for the purpose of making some change. Let's drop here a section three. Save that.

    Let's edit, let's commit it. Now you can see that everything is still clear. I am a master. I create a new commit. Now I can jump back to my app folder branch. I can do a git stash pop to take it out again.

    Let's first take a look at what we have in that stash. You can imagine that stash as a stag structure where all the messages will pop in one after the other. We'll have here stash@{0stash@{1}, and so on.

    I can now do something like git stash pop which basically takes it out of my stash stag. If I do stash list, we can see it's empty. I have all of my files again here.

    Let's again stash them. If I do git stash list, we see they are still in there. Now I could also instead of doing a pop, because I want to leave them in there for some reason, I could do a git stash apply.

    What git stash apply will do is it will take out the changes again into my working directory just as the git stash pop did. If I do git stash list, I can see it's still in there.

    Additionally, what you could do is also when stashing new changes to give them a name, in order to remember what kind of changes you actually put in there. What we can do is instead of just git stash, we can do git stash save. I am giving it a name like WorkInProgressAppFolder.

    Let's do a git stash list. Now you can see at the point 0we have basically that WorkInProgressAppFolder. At stash@{1} we have all the generated messages which the git stash command adds for us automatically.