DEV Community

Discussion on: 8 underrated git commands every programmer should know (not the usual pull, push, add, commit)

Collapse
 
dentych profile image
Dennis • Edited

Hmm.. I'm a little split regarding this article.
It's nice to see an article that's not "how to commit and push". However, some of these seems a little unnecessary.
I have a few comments:

  1. git push origin -u <branch> does not rename anything. It pushes the local branch and sets the upstream for remote tracking.

  2. --soft is the standard setting for git reset (and thus is not needed). HEAD~1 is the same as HEAD^, which is easier to write.

  3. Same comment as above regarding HEAD^

  4. git stash apply will not remove the stashed item(s) from the stash list. Using git stash pop will apply the stash and then remove it from the stashed items list. If you use apply, you will manually have to drop the stashed item afterwards, as in 99% of the cases you will not want to keep the stashed items after they've been reapplied to the current branch.

  5. This just seems unnecessarily cumbersome. You can just do git log, find the commit you want to reset to and do git reset --hard <sha>. You would also be able to just do git reset --hard origin/branch, as in most cases you wouldn't have pushed. Using HEAD@{xx} is entirely unnecessary, in my opinion, as you can use git shas, branch names and other things that makes more sense.

Collapse
 
chaelcodes profile image
Rachael Wright-Munn

2 & 3 - it's better to get comfortable with HEAD~1, because you can HEAD~2. If you only learn HEAD^, then you only learn to go back 1 commit.

5 works post-rebase. git log does not.

Collapse
 
dentych profile image
Dennis • Edited

You can do HEAD^^^^^ to go back 5 commits, so in reality it's the same. I find it easier to write ^, but it's really up to personal preference :)

5 works fine post-rebase. git reflog can be very confusing for newbies, because it shows a log of where the HEAD has moved, and not just a (probably) fairly linear commit history.

Collapse
 
milindsoorya profile image
milindsoorya

Reading the post again the second point does feel a bit misleading . Made some changes to make it clearer and thanks for the comment, appreciate it.

Collapse
 
dentych profile image
Dennis

I like 2 better now :)

And I'm glad you took the comment as well-meant feedback!

Overall, a fine post :)