Nifty Git “Trick”


Git’s branching facilities are awesome. We all know that. However, if you’re like me, I don’t always have the foresight (or discipline I guess) to always create a branch before I dive head first into a refactor.  Then I learned about Git’s “stash” command’s ability to create a branch from what you’ve stashed, leaving  your current branch untouched. How awesome is that? Check it out:

  1. Make some changes. Stage them (stash stashes staged changes)
  2. run “git stash”
  3. run “git stash branch branchname” where ‘branchname’ is the name of the branch you want to create

And Viola! You know have a branch created from the changes you stashed. You can then use the standard merge facilities to merge that branch back into the one you were working on (or any other branch for that matter).

Isn’t that f’ing cool?

0 Responses to “Nifty Git “Trick””



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s




Twitter


Follow

Get every new post delivered to your Inbox.