Hacker News new | past | comments | ask | show | jobs | submit login

Merge Conflicts.

I think a lot of tutorials spend a lot of time teaching you the index/staging (a non-trivial concept that beginners don't need) but don't teach you how to survive merge conflicts and other common tricky situations which beginners are likely to run into if they're collaborating.

Your list is all you need...until you try to `git pull` and it says

> Cannot pull with rebase: You have unstaged changes.

You're only option with your list is commit your changes, but I think it's better to `git stash` then `git pull` then `git stash pop`

Though when you `git pull` you can get a merge conflict and there's two different ways to resolve it depending on if you used the `--rebase` flag or not.

Once you're done resolving those conflicts, you run `git stash pop` and could possibly get yet-another merge conflict that needs to get resolved.

Basically, I'd add `git stash` to your collaborative list. You can't `git pull` without it.




> Basically, I'd add `git stash` to your collaborative list. You can't `git pull` without it.

Of course you can! Git stash is not necessary for any workflow, it's pure convenience.

Best practice is not to pull with unstaged changes. If you want to, then:

  $ git commit -am "WIP"
  $ git pull --rebase
Easier than stashing! But this does mean you're going to need to rebase -i later before you push.

Stash is dangerous for beginners, I don't recommend learning it first. From the stash man page:

"If you mistakenly drop or clear stashes, they cannot be recovered through the normal safety mechanisms." https://git-scm.com/docs/git-stash


Sure, but my guess is it's just as easy to shoot yourself in the foot with rebase -i. Beginners are still going to have a hard time recovering mistakes with rebase -i, even if it's theoretically possible to recover.

Plus, now you need to use `git diff origin` rather than `git diff` to see your changes.


> Sure, but my guess is it's just as easy to shoot yourself in the foot with rebase -i.

No. rebase -i goes in the reflog. stashes don't. The rebase man page does not have the same safety warning that the stash man page does. I have personally witnessed a lot of stash accidents, and not many rebase accidents.

With a rebase, if you have a bad merge conflict, you can abort. With a stash you can't. If you've committed your changes and have problems either forgetting what you're doing, or with merge conflicts, or with being in the wrong branch. All of these cases have more undo options with commits. In the worst case, you still have the safety net of the reflog with commit. With stashes, your only safety net is hunting for dangling blobs using fsck.

Previous threads: https://news.ycombinator.com/item?id=12613062 https://news.ycombinator.com/item?id=12622414


I mean it's just as easy to make a mistake in the first place with rebase -i. Even though one is theoretically possible to recover with rebase -i, it's going to be very hard to recover for a beginner. (You need to know the reflog command, etc.)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: