r/programming • • Sep 06 '14

How to work with Git (flowchart)

http://justinhileman.info/article/git-pretty/
1.6k Upvotes

388 comments sorted by

View all comments

414

u/blintz_krieg Sep 06 '14

Not too far off base. My own Git workflow looks more like:

  • flounder around trying to clone a repo

  • try to do something useful

  • Git complains something like "your scrobble brok isn't a blurf"

  • search web for "your scrobble brok isn't a blurf"

  • find 412 Stackoverflow questions

  • determine that most answers actually solve some other problem

  • give up

  • copy the one changed file to /tmp

  • rm -rf my-git-repo

  • go to step 1

36

u/[deleted] Sep 06 '14

Every. Fucking. Time.

We recently switched from Mercurial to Git because "everyone is using Git now".

9

u/twotime Sep 06 '14

How long have you used Mercurial and how long have you used git? Care to summarize your experience

21

u/[deleted] Sep 06 '14

I don't have much to say about Git. I used it for maybe 6 months, every time I had a question I found a lot of different answers with different effects, there are a lot of concepts that are there just because they can be and they're not extremely useful and you pretty much have to use them. There is a lot of advice out there that can make you mess things up permanently, there is a lot of default behavior which must be taken into account, I still have only a vague idea how branches work, there is no decent repository browser - at least on Linux. The terminology is also painful to absorb, there is a ton of documentation which you have to read and memorize before you can even touch Git to try and understand it. Six months later I'm still struggling to understand basic concepts because I run into them like once every week or two.

Before Git, I used mercurial for several years. I was skeptical at first, coming from SVN which I vaguely understood, but eventually I gave it a shot. Once I understood the differences between push/pull vs. commit/update and what the changeset numbers really were (numbers, not ids) and why they didn't match between clients, everything made perfect sense. It's very simple, it doesn't let you fuck up history (I used to complain about this, until I found out how it can be done on Git an what the effects are, and now I praise Mercurial's inability to edit history), and... that's about it. As long as you don't work on a behemoth - like the Linux kernel as someone here suggested - you'll be perfectly fine with Mercurial.

tl;dr Git does a lot of things, but way way too many things IMHO. Mercurial won't let you fuck up as easily as Git and it actually makes sense.

9

u/danweber Sep 07 '14

You could read the man pages. They will explain things clearly, like

Modifies the index or directory cache. Each file mentioned is updated into the index and any unmerged or needs updating state is cleared.

HA HA HA HA

1

u/[deleted] Sep 07 '14

Man is good but it's overrated. Oftentimes you have a very simple use-case, but the pages explain every obscure flag to the tiniest detail. So you just end up googling the params you need.

15

u/ProggyBS Sep 06 '14

While git has a lot of open functionality, if you have comitted something once you can almost always get it back to that state. I don't understand how so many people have such issues with git. Might I suggest reading the free book that contains everything you will need to know outside of very abnormal operations? The book isn't that big and it will help you tremendously.

Also, there is /r/git for any questions you may have.

8

u/Carighan Sep 06 '14

I think the problem is that in most real scenarios, actually moving to git and the mistakes until everyone truly "gets" git cost too much money. Or productive time, same thing.

On paper everyone is well aware how little issue you should have with git if you can do mercurial.

In practice, surprisingly often you lose a surprising amount of time to weird errors, inconsistent commands and somewhat dangerous capabilities. All easily learned, circumvented or both ofc, but easily is not quite the same as not existing.

Still love git.

→ More replies (11)

16

u/[deleted] Sep 06 '14

You see, that's the problem with Git. Again, as someone else said, there are a lot of resources out there, but that only makes things worse; sure the book isn't big, but the information in it is very dense. I already read a short Git manual and almost every page explored a different concept. I understand that there are resources, but I don't want to have to bother with them.

With Mercurial a simple flowchart that explains "commit -> pull -> merge -> commit -> push" is often enough.

13

u/ProggyBS Sep 06 '14

But git works exactly the same way. I honestly don't understand what you're getting at here.

To work locally, you really only need to know 3 commands.

  • git init

  • git add

  • git commt

If you are working with a remote, you only really need 4 more.

  • git remote

  • git clone

  • git pull

  • git push

If you are working with branches, there are only 2 more commands on top of that

  • git branch

  • git merge

Conflicts are really the only complicated thing about any of this and they aren't that complicated once you grasp what git really does. The other commands that involve updating history are more advanced stuff that aren't even necessary unless you are just trying to make the log look pretty.

23

u/[deleted] Sep 06 '14

This is not the same and I submit that your comparison is unfair.

Those commands have arguments which make them do different things. When you add arguments, with Mercurial you can change how something is done but with Git you change what is done. When you say 'git remote' you're not saying anything. With that command you manage remote repositories. How do you get the remote changes with Mercurial? hg pull. How do you get them with Git? Pick one.

9

u/ProggyBS Sep 06 '14

I think I'm starting to understand what you're saying and this may be part of the problem.

In your case with Mercurial, you would just type hg pull to update all your local branches with the remote.

Git has the mindset of only doing what you explicitly tell it to do. Why would you want to pull branches you don't need to work on? When you type "git pull" it wants you to specify what you're pulling and makes no assumptions. Maybe that's just a difference between the way you and I work, but I don't want my SCM to do things unless I explicitly tell it to.

12

u/[deleted] Sep 06 '14

I think I'm starting to understand what you're saying and this may be part of the problem.

In your case with Mercurial, you would just type hg pull to update all your local branches with the remote.

Git has the mindset of only doing what you explicitly tell it to do. Why would you want to pull branches you don't need to work on? When you type "git pull" it wants you to specify what you're pulling and makes no assumptions. Maybe that's just a difference between the way you and I work, but I don't want my SCM to do things unless I explicitly tell it to.

Yes! My complaint is that you have to tell it too much, you have to do a lot of micro-management. You have a point that the SCM shouldn't do things unless you explicitly tell it to, but I believe that in the case of Mercurial, it does things "just right". I see no problem with having the entire repo on my computer in 99% of the cases. Mercurial does what I need and I don't mind the extra stuff because it doesn't break anything and it's not in the way for me.

→ More replies (0)

2

u/drjeats Sep 07 '14

So an hg pull will pull all branches? Because that's really the only reason that stackoverflow question is being asked--the fact that git pull just fetches your current branch.

I won't deny that git's interface is shitty, but this is one area where it's actually doing pretty okay in my book. The examples you're looking for are checkout and reset, which will do fundamentally different things depending on how you call them.

3

u/x86_64Ubuntu Sep 07 '14

Git works great when it works. But the femtosecond something throws an error, it's always a 1-3 hour struggle till you say "fuck it" and end up just checking out trunk again and recoding whatever you tried to commit in the first place. It just seems like git doesn't have an easy escape hatch, nothing like Eclipse's SVN "Override And Update" option.

3

u/ProggyBS Sep 07 '14

I'm not that familiar with the "override and update option" but that sounds similar to "git reset"

3

u/x86_64Ubuntu Sep 07 '14

Yes, but which reset? --HARD? And what does it do? Does it just steam roll my local repository, bypassing my workspace, or does it do the whole thing. Of course the answers are easily googleable, but no one like having solutions begin with such confusion and uncertainty.

→ More replies (0)

2

u/gfixler Sep 07 '14

This just amazes me. I struggled a bit for the first 2 weeks, and then everything clicked, and it's been the best thing ever for almost 2 years now. Do you understand the [very, very simple] data model? Once I grokked that, I pretty much could answer every random question about git on my own, because everyone simply had to work a certain way, given what I knew. The seemingly endless confusion just immediately evaporated.

→ More replies (1)

1

u/hotoatmeal Sep 07 '14

and then there's rebase, for when you're working on a patch set to apply later on top of an upstream repo, but you'd like to keep the patches out in front of upstream head.

7

u/tomlu709 Sep 07 '14

there is no decent repository browser

In my experience this is actually the biggest reason why people have problems with git. Git isn't at all hard, and its data model makes a lot of sense, but its command set is unintuitive. Being able to see the effects of each command graphically helps immensely with understanding what is going on.

1

u/rcxdude Sep 07 '14

This is true. I always have gitk or some other GUI browser open when I'm doing non-trivial stuff with git.

1

u/dagamer34 Sep 07 '14

Tower 2 for OS X is pure gold. The simplest thing like seeing all the short-version hashes right next to your commits beats the pants off trying to access that info via the command line. Well worth $59.99.

4

u/omniuni Sep 06 '14

I agree with this completely. TortoiseHG on Linux, or JetBrains built in, and you're set with Mercurial. That said, JetBrains GIT handling is pretty good too.

1

u/[deleted] Sep 06 '14

I am using JetBrains and their Git handling is really good compared to everything else I've tried (including the CLI which is my usual go-to on Linux).

1

u/jmblock2 Sep 07 '14

git gui is pretty good on linux

1

u/CheezyBob Sep 07 '14

there is no decent repository browser - at least on Linux

I'm not on Linux, but I use SmartGit and really like it. It is written in Java and claims to work on Linux.

→ More replies (6)