From the course: Working with LinkedIn Learning Exercise Files on GitHub

Stash changes with Stash - GitHub Tutorial

From the course: Working with LinkedIn Learning Exercise Files on GitHub

Stash changes with Stash

- [Instructor] Whenever you make changes to files within a particular branch, you typically need to resolve those changes by committing them, that is saving them locally. Or rolling them back before you switch to another branch. But there are times in your workflow when you might want to save changes temporarily without committing them to the repository. And you can do that with a Git operation called stash. In this example, I'm working with this file, main.go, using the Go programming language. And we're going to add a little bit more code here. I'll say fmt.printf and then the variables length is. And then %d, which is a placeholder. And then \n, that means a line feed. And then I'll pass in the value that will go where that placeholder is. And that'll be len for length. That's a function and I'll pass in a string. I'll save that change and I'll test it. I'll view the debug console. And I see the variable's length is 11. Now, I'll switch back to GitHub Desktop and I'll see that there's a change here. And as I showed earlier, I can look at the difference between my current code and my new code. Now, let's say I wanted to switch to another branch, but I don't want to save that change permanently. I can go to the menu and choose Branch, Stash All Changes. When you select that menu choice, you'll immediately save your changes into a stash. And if you go and look at your code in your editor, you'll see it's back to the original state. You can now switch to any other branch and do whatever you need to do. And when you come back to GitHub Desktop, you should see this display, View your stashed changes. Click View Stash, and then click Restore. Now, go take a look again in the editor. And that new code is back where you put it. From this point, you can now commit, or save your changes, or you can roll them back. Either way, stashing gives you the ability to temporarily save your changes while you go off and do something else. And you're not making long-term changes to your repository.

Contents