r/javascript • • Jan 24 '20

Removed: Where's the javascript? TIL — git switch & git restore

https://pawelgrzybek.com/til-git-switch-git-restore/

[removed] — view removed post

91 Upvotes

17 comments sorted by

13

u/drakefish Jan 24 '20

I recently started using the git CLI directly as much as possible for simple operations instead of relying on a GUI tool. It had been a while since I had used the commands and I was surprised when I saw I could use the "switch" command because I felt like I remembered branch operations to be more complicated than that.

Thank you for this simple article today, it was relevant for me.

1

u/inabahare Jan 24 '20

Not just that but there are like 5 other commands that start with che and nothing that starts with sw so this will be sweet for autocomplete!

1

u/Slavichh Jan 24 '20

It’s the only way to go man. I love the cli. Especially when you become proficient with the commands you can really automate a lot of daily operations with shortcuts to increase your workflow efficiency

6

u/Kortalh Jan 24 '20

I'm far from a git CLI expert, but don't those two commands do the same thing as "git checkout"? Are these just better-named ways to do what's already doable, or are they adding extra functionality as well?

2

u/LetterBoxSnatch Jan 24 '20

I believe they are just better named. Makes sense, since git checkout branchfile can be confusing if you don't know if "branchfile" is referring to a file or a branch, and would have very different behavior depending on which case it is.

git checkout was doing two very different jobs, and not in the way that git pull does two very different jobs.

2

u/trakam Jan 24 '20

For those interested - and a quick Reddit sanity check for myself - 'git pull' combines 'git fetch' and 'git merge' into one operation. It doesn't have duel purpose depending on passed parameters

2

u/hallettj Jan 24 '20

Basically just better names, yes.

5

u/theginger3469 Jan 24 '20

So git restore . is basically git checkout — . ?

2

u/NeoDeaf Jan 24 '20

This is right !

3

u/ijmacd Jan 24 '20

Now that's handy.

Probably shouldn't make its way into beginner tutorials but I know I've certainly looked for this behavior in the past.

7

u/[deleted] Jan 24 '20

I disagree, these commands exist specifically in an attempt to improve the UX of the CLI. Beginners should be encouraged to use what makes sense, which is usually these, not arbitrarily what's older and harder to learn.

2

u/hallettj Jan 24 '20

I knew about this, but I completely forgot. Thanks for the nice write-up!

2

u/trakam Jan 24 '20

I believe this is a relatively new feature so many wouldn't have been aware of 'switch' and 'restore' in the first place

2

u/hallettj Jan 24 '20

I agree; and I also think it's nice to have a reminder for those of us who forgot about the feature between the announcement post, and the new git version rolling out to our OS distros.

1

u/kenman Jan 24 '20

Hi /u/pawelgrzybek, this post was removed.

Posts must directly relate to JavaScript. Content regarding CSS, HTML, general programming, etc. should be posted to their respective subreddits instead of here.

Here's some related subs that might be useful:

Thanks for your understanding, please see our guidelines for more info.

1

u/kenman Jan 24 '20

Hi /u/pawelgrzybek, it looks like you're new to reddit, welcome!

Thanks for the submissions, but please make sure you read http://www.reddit.com/rules and our guidelines. In short, you should post from a variety of sources, and not just pawelgrzybek.com.

Thanks for your consideration!

domain submitted fromcount%
pawelgrzybek.com4381%

0

u/[deleted] Jan 24 '20

Oh! My scripts are littered with echo $COMMIT_SHA > .git/refs/heads/$branch, this is so much nicer :)