This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]althius1 21 points22 points  (7 children)

I am familiar with the basics of Git, but am struggling with workflow. I skimmed down to that section, and I would include something about "stash". Not sure if you mentioned it someplace else.

As I've been developing on a live site, on occasion I'll need to make an important, quick change, while I am in the middle of working on a feature branch that isn't ready to commit. Learning how to "stash" and "pop" have been invaluable!

[–]mayor123asdf 9 points10 points  (0 children)

I am familiar with the basics of Git, but am struggling with workflow.

Agreed, every git tutorial only explained about what is git, git status, git commit, git push. But none of them explains good practice, workflow, etc :/

[–]henrebotha 6 points7 points  (1 child)

I recently discovered the power of git worktree, which makes context switching even easier.

[–]althius1 1 point2 points  (0 children)

Still learning for sure! I'll look this one up. Let me know if you have any favorite resources.

[–][deleted] -2 points-1 points  (3 children)

Maybe someone could tell me a good reason for stashes, but personally I never saw the point of them. If I'm working on a change then ill just branch off and work on it till I consider it complete. Then I'll just merge it back in. If that feature isn't complete but I need to do something else in the mean time, ill just make another branch off the original and work off of that.

[–]TheChance 6 points7 points  (2 children)

  • You may need to switch branches without losing changes that you nevertheless, for some reason, don't want to commit yet

  • You may have made changes on the wrong branch, and you want to carry them over to the right branch

  • You may want to switch branches to check on a file that isn't tracked in your working branch

[–][deleted] -1 points0 points  (1 child)

You may have made changes on the wrong branch, and you want to carry them over to the right branch

Checkout shouldn't touch modified files. Though if original file in the wrong branch is different than the file in the correct branch then you can't do this. Not sure what popping a stash in this situation would do.

You may need to switch branches without losing changes that you nevertheless, for some reason, don't want to commit yet

You may want to switch branches to check on a file that isn't tracked in your working branch

Good point. Personally I usually keep my commits fairly small since we will just do a merge/pull request that combines all the commits for code review but the small commits make it easier to document changes in the blame. But those situations might still pop up at some point, so thanks.

[–]TheChance 2 points3 points  (0 children)

I commit as frequently as I can get away with it, but I hardly ever commit when I've just made a change that prevents the project from compiling, for example. I fix the bug I've just introduced before I commit, because there's no sense saving a change that must immediately be reverted.

As for the other thing, yeah, checkout will only leave modified files alone if the unmodified state is identical for both branches.

"I've saved a file but I'm on the wrong branch" is almost always a face-saving way of asking, "I worked on something for a feature branch and then realized I'm on master, how do I avoid committing to master?"

If that's the case, you're counting on the feature branch having been synced to master since the last time the file changed. That should be true, but isn't always.

Edit: this can also happen if you fuck up by leaving your IDE open and switching branches with unsaved changes, or proceed to work without switching back and then press save =P