Hacker News new | ask | show | jobs
by nneonneo 2375 days ago
Also worth noting: you can abort and undo many kinds of in-progress operations with “git <operation> —abort”. Works for merge, rebase, and a few other things, and can seriously save your bacon when you do a “git merge <badbranch>” and are suddenly confronted with a bazillion merge conflicts.

Also, if you’re in a panic because something went screwy, check “git status” and read every line carefully. status tells you a lot more than you might expect - what branch you’re on, if you’re even on a branch, what merge/rebase/commit operation you’re in the middle of (if any), and even how to go forward with or back out of the current operation.

Finally, commit regularly and often! reflog and rebase mean that you can always maintain a clean history if you want, while committing makes sure that your changes are properly tracked and saved by git so you can rewind when needed. Once you get comfortable with it, git lets you really practice fearless experimentation, which unlocked a whole new level of productivity for me.

3 comments

> check “git status” and read every line carefully.

Seconded, but I'd go even further. Run and read git status before and after running any git command until you get comfortable enough with git to where you can predict the output without running it.

Additionally you can go get git prompt[1] installed so you always know your git status at a glance. Saves a lot of typing in any case.

As a last suggestion I'd say go read git-scm.com[2]. It has the excellently written man pages for looking up what a command does and which flags it takes. It also has an amazingly written free ebook explaining git top-to-bottom. After reading that you'll be a git wizard compared to your peers.

[1] https://github.com/git/git/blob/master/contrib/completion/gi... [2] https://git-scm.com/

I totally second reading the book front to back. It is not that long and fairly well written, and can save so much time and frustration in the long run. Giving the link is the first thing I do when helping someone with git.

Unfortunately so many people put that aside and never read it, and then come back to me a few weeks later because they messed everything up again, and still do not understand what I mean with "index".

Git is very powerful but a bit awkward, so I consider knowing the underlying concepts necessary to use it properly.

I don't even think git is all that awkward. It's incredibly elegant but that also makes it somewhat orthogonal compared to how you're used to think about stuff.

I dunno, git is probably one of the few instances where I feel like RTFM is a valid remark.

Weirdly there is no "git stash pop --abort" to roll back when a merge conflict occurs during stash pop.
You can also use git-retain-history with reflog to sidestep unexpected git operations.

https://git-man-page-generator.lokaltog.net/#4b16e11f044dd60...