Skip to content

Commit 55c3aa8

Browse files
committed
docs(17-Stashing): Create stashing chapter
1 parent 6c33f69 commit 55c3aa8

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

docs/17-stashing.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Stashing Changes
2+
3+
We all know what squirrels and other animals do, the put away food for harsh times. They create a secret stash.
4+
5+
Mush like this, Git also has the ability to stash.
6+
7+
Stashing is simply putting work aside whilst you do something else.
8+
9+
## Stashing
10+
11+
A common situation for the use of stashing is when uncommitted changes get in the way of branching.
12+
13+
This often occurs when one branch is ahead of your working copy. The act of switching to the other branch would then lead to git clobbering your changes.
14+
15+
Thankfully, Git will not let that happen.
16+
17+
So what do you do? Have a think how you could resolve the problem.
18+
19+
### This is one possible solution
20+
21+
So when the above scenario occurs you would have to:
22+
23+
- Copy the changes – you are not sure what files changed, so you probably grab everything (yuck!)
24+
- Copy to another folder (yuck yuck)
25+
- Use git reset --hard to DESTROY the working copy changes (yuck yuck yuck)
26+
- Switch to the branch
27+
- Do work
28+
- Switch back, copy all the files back and really really hope you didn’t stuff everything up
29+
30+
### Or... Making Life Easier
31+
32+
That is both nasty and long winded... so we can make it easier by using a stash of changes:
33+
34+
- git stash
35+
- switch
36+
- switch back
37+
- git stash pop
38+
39+
And there you have it... we are done!
40+
41+
## This is a Public Service Announcement
42+
43+
Git stash is sometimes not taught in an introduction to Git.
44+
45+
The problem with this it that it is just about the most useful command you can find to make working with Git seamless.
46+
47+
This is particularly true if you are branch/working with a remote, that is, using git as intended!
48+
49+
# Time for your Supplements
50+
51+
This video is on Git Stash... The audio at the start may be a little off centre.
52+
53+
<iframe width="560" height="315" src="https://www.youtube.com/embed/adzewZEj2Pg?si=KJKuu2p7pTi3soDL" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
54+
55+
# References
56+
57+
Adhikary, T. (2023). _10 Git stash commands every developer should know_. [online] GreenRoots Blog - Tapas Adhikary. Available at: https://blog.greenroots.info/10-git-stash-commands-every-developer-should-know [Accessed 15 Mar. 2024].
58+
59+
Programming Peanut (n.d.). _[Git] What is Git Stash and how to use it_. [online] www.youtube.com. Available at: https://www.youtube.com/watch?app=desktop&v=adzewZEj2Pg [Accessed 15 Mar. 2024].
60+
61+
62+
63+
---
64+
65+
[Undoing Changes](docs/16-oopsy-undoing-changes.md) | [Workflows](18-workflows.md)

0 commit comments

Comments
 (0)