-2

Let's say I'm on branch A and I do some changes on the branch. For some reason, I need to check out to branch B But the problem is I don't wanna commit them yet. I just wanna keep them without committing them. I already tried stashing using git add . and then git stash. But I'm not sure if I do it right because after I run git taste. it automatically removes my changes. and when I switch to another branch and then switch back to that branch, all the changes disappeared. what should I do in this situation? Any advice?

Filburt
  • 16,951
  • 12
  • 63
  • 111
  • `git worktree` is one of the options. https://stackoverflow.com/questions/31935776/what-would-i-use-git-worktree-for – ElpieKay May 30 '22 at 08:30
  • 2
    "I don't wanna commit them yet" -> Why? A local commit can't break anything. Just commit without pushing. When you'll resume work on branch A, just undo the commit while keeping changes in place with `git reset HEAD^`. Of course, stashing somewhat automates this, but stash entries come and go... a temp commit stays on its relevant branch. – Romain Valeri May 30 '22 at 08:37
  • You can have a look at `--include-untracked` and `--keep-index` options to `git stash` command. Also, use `git stash` to save changes and `git stash pop` to apply them back. – Krzysiek Karbowiak May 30 '22 at 09:03
  • What is `git taste` above? Presumably it is some alias you have for some other Git command...? – torek May 30 '22 at 11:31

1 Answers1

1

It sounds like you need to pop the stash - It doesn't automatically get applied to the branch after you check it out.

Use something like git stash pop or git stash apply

See the documentation for git stash.

Kyle Trauberman
  • 24,976
  • 13
  • 86
  • 117