2

My typical workday involves reviewing other devs' code and fixing multiple bugs at once. Are there any methodologies to quickly checkout a branch without having to interrupt your work in the current branch?

I do this many times per day and frequently forget which step I'm on.

  1. git stash

  2. git checkout feature-b

  3. git pull

    ... make some commits, etc ...

  4. git push

  5. git checkout feature-a

  6. git stash pop

Edit: Multiple directories are cool, but I don't think it's necessarily the only way to solve this.

Community
  • 1
  • 1
Daniel Node.js
  • 6,734
  • 9
  • 35
  • 57
  • That seems like the typical stash-based workflow many people use. I'm not sure what you mean by "frequently forget which step I'm on"? – jingx Jul 09 '18 at 20:46
  • @jingx It's another workflow that I have to keep in my working memory. I'd rather spend my brain resources on the problems I'm solving. – Daniel Node.js Jul 09 '18 at 20:51
  • Well, if you mean you don't want to remember which branch you were on, I suppose you could do local clones of the same repo, each having one branch checked out. But then you still gotta remember which _directory_ you were in, instead of branch, so we are back to square one... – jingx Jul 09 '18 at 20:56
  • @jingx That's interesting. – Daniel Node.js Jul 09 '18 at 20:58
  • If your Git is too old (pre 2.5), consider the multiple clone solution @jingx mentions. Note that local clones share underlying data storage, at least initially (eventually they grow apart). If you have `git worktree add`, that's probably the way to go; there you're literally sharing the underlying repository, so there are fewer disk-space issues and synchronization is automatic. – torek Jul 09 '18 at 21:10
  • Possible duplicate of [Git - Store branches in separate local directories](https://stackoverflow.com/questions/5101270/git-store-branches-in-separate-local-directories) – phd Jul 09 '18 at 21:36
  • It might not be the *only* way, but it is the best way ;) – VonC Jul 09 '18 at 21:53

2 Answers2

2

A better workflow would be to use the git worktree command, which allows you to checkout different branches (of the same repo cloned only once) in different folders.

That way, no more stash to do, only a pull in the right folder.
You current work in a given branch remains untouched, unmodified, while you are doing a review in another folder/branch.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

I would:

  • Save all work
  • Make a Work In Progress commit
  • Switch branches

I don't trust stashes enough to save work in them. I might just save a local config setting or something that isn't critical.

Joe Phillips
  • 49,743
  • 32
  • 103
  • 159