9 ms·
Understanding Git for real by exploring the .git directory
- jrbancel 11y agoThe most enlightening introduction to git internal model (graph of commits) and how the main commands alter it I have read so far: https://jwiegley.github.io/git-from-the-bottom-up/ https://jwiegley.github.io/git-from-the-bottom-up/ I think it is slightly more relevant to understand the model than the .git/ structure since the .git/ folder is just an implementation detail.
- paulddraper 11y agoThe point of this is to also understand just the implementation.
- chmaynard 11y agoCould someone please post a link to a PDF version of this article?
- blacksmith_tb 11y agoFor offline use? But git is a dvcs... ahem, anyhow, wkhtmltopdf[1] is a reasonable choice for converting arbitary urls to pdfs, and can be installed via apt, homebrew cask etc. [1] http://wkhtmltopdf.org/ http://wkhtmltopdf.org/
- sghodas 11y agoI saw this posted a couple years ago, but it was a great guide to starting out with git: http://pcottle.github.io/learnGitBranching/ http://pcottle.github.io/learnGitBranching/
- swsieber 11y agoI just have to say, I've gone through that guide and it was great. It really helped me understand the refs (branching) model. It was a couple of years ago, so it may be even better now. Thanks for posting it. I always had a really hard time trying to track down the link.
- empath75 11y agoI've been using git at work for a couple of years and I haven't spent very much time thinking about the internals at all. It just seems to work pretty much, though sometimes I get into a weird state and just delete and redownload.
- sethrin 11y agoThat's the thing, there is almost no reason to ever have to delete and redownload. Moreover, the reason that git is dominant is (network effects, and) because it is solving the right problem with the right internal abstractions. It has even managed to become popular in spite of its user interface.
- empath75 11y agoYeah usually there's a way I can figure it out but if it takes more than 15 seconds it's easier to just clone the repo again.
- recursive 11y agoThere is a reason to re-clone. It fixes every weird git state. And you don't even need to learn a bunch of theory to do it.
- sethrin 11y agoWe are all ignorant in most respects; there is an opportunity cost in knowing anything. If you use git daily, I submit that it does not make sense to be ignorant of how it works. Yes, you will take no physical harm from misusing this tool, but you're setting yourself up for failure. Reading about how git works will prevent you from making the mistakes that lead to an unworkable state, and allow you to resolve any unexpected situations or errant keystrokes. To make something of an analogy, git has the most powerful and flexible form of "undo" that has been conceived to date, and you are discarding this because you can always re-download an old copy and redo your work. If it is something that you use only rarely, there is nothing wrong with choosing to study other things. If you are employed as a software developer then I would consider you to have very little excuse for ignorance.
- chx 11y agoObligatory link to Charles Duan's most excellent git tutorial: > you can only really use Git if you understand how Git works. Merely memorizing which commands you should run at what times will work in the short run, but it’s only a matter of time before you get stuck or, worse, break something. http://www.sbf5.com/~cduan/technical/git/ http://www.sbf5.com/~cduan/technical/git/ Somehow I do not see this mentioned often despite it is, in my opinion, hands down the best tutorial for git. Not too short, not too long, not too simplifying, not too complicated. Just right.
- chmaynard 11y agoIs this article available as a PDF document?
- octref 11y agoI feel this one is more well-written and complete: https://codewords.recurse.com/issues/two/git-from-the-inside-out https://codewords.recurse.com/issues/two/git-from-the-inside...
- asattarmd 11y agoThat and The Git Parable (http://tom.preston-werner.com/2009/05/19/the-git-parable.html http://tom.preston-werner.com/2009/05/19/the-git-parable.htm...) gave me a wonderful understanding of Git.
- mosquito242 11y agoI'm finding this comment thread to be a great example of the idea that everyone has different and particular learning styles. 6 comments, 4 different git tutorials (not counting the original post.)
- bhrgunatha 11y agoEveryone has their favourite explanation of how git works. Mine is: Knowledge is Power: Getting out of trouble by understanding Git by Steve Smith [1] [1] https://www.youtube.com/watch?v=sevc6668cQ0 https://www.youtube.com/watch?v=sevc6668cQ0
- mr_luc 11y agoI worked with someone whose approach was very interesting: he committed the .git directory of a newly initialized repo to a separate, newly initialized repo. And then watched what changed when he added a file, changed things, branched, etc, in the committed .git directory. It's always seemed worthwhile to me to dig into git's model more, but if you're already comfortable and productive with stuff like detached head/rebasing/basic workflows, it's hard to justify when you're already trying to find time to learn new languages, frameworks and devops tools ...
- TheWiseOne3 11y agoI missed the part where that was interesting
- n0us 11y agofor about six months my git workflow was this: git add -A git commit -am "fixed some stuff" but I've finally found some time to start digging into how to really use it. The issue I have with it is that if you step outside the basics it's so easy to get yourself into a thorn bush and the way that git is explained most places is really not intuitive at all.
- EvanPlaice 11y agoTry using a tool like 'git cola' that allows you to selectively commit soecific lines, instead of just by file. Start a project and attempt to maintain a clean history. Break up changes logically into separate commits. To the point where 90%+ don't need more than the subject to describe a change and the history can be read like a story. Use 'gitk --all' to view the tree of changes. get comfortable with using feature branches, using interactive rebasing to clean up a messy history of changes, etc. The CLI works great for most things but visual tools make it much easier to write a clean history and reason about the changes over time.
- tuxracer 11y agoYou can also commit specific lines using `git add -p`
- twampss 11y agoFor anyone looking for a video/demo on this, here's a great presentation by Tim Berglund - https://www.youtube.com/watch?v=MYP56QJpDr4 https://www.youtube.com/watch?v=MYP56QJpDr4
- zyxley 11y agoI look at this, and then I look at people wondering why non-coders don't use version control, and I laugh and laugh.
- detaro 11y agoI don't think this article is a very good argument why non-coders don't use it. They don't care about the internals. Git's CLI, well, that's a good reason why they don't. (but you can get quite a lot of the benefits with a few basic commands via a GUI tool, and you totally can explain that to many non-coding users)
- bbcbasic 11y agoNon-coders do use version control. e.g. MS Word documents have some version control features, as does Atlassian Confluence. Some even use Git!
- sriram_iyengar 11y agoNice article. https://codewords.recurse.com/issues/three/unpacking-git-packfiles https://codewords.recurse.com/issues/three/unpacking-git-pac... is another article that i found very useful to understand packing and unpacking. (I found this when I was building a standalone html viewer for .git directory)
- justACommenter_ 11y agoI've downvoted this post for using an xkcd cartoon. This comic has become cliche and no one really likes it anymore. Avoid stupid cartoons if you write a technical post, especially xkcd that's so overused.
- forrestthewoods 11y agoHow many "Understanding Git" posts have hit #1 on Hacker News? More than a few. How many have hit top 10? Surely dozens. Can we, please, take this as an indicator that Git is too fucking complicated? After the first thousand "Git made easy" blog posts it should have been apparent. Le sigh.
- quadrangle 11y agoBut maybe everyone agrees that it's too complicated but it's used. You know, English is way too complicated, but you can't just make everyone switch to Esperanto. People are interested in things that help people understand English and things that help people understand Git.
- na85 11y agoI think most of us do agree. The official documentation is written as though the reader is already intimately familiar with the internals of git. I'm a smart guy, and I've read the official docs numerous times but every single time I failed to come away with a greater understanding than I had before. The commands are not particularly intuitive either. I personally think git is fucking awful. ... but it's the best version control system anyone's come up with so far. It sucks less than the alternatives and I use it for all my projects.
- forrestthewoods 11y agoI work in video games where everyone uses Perforce. It's not perfect but I think it's vastly superior to Git. I can train someone whose never even heard of source control how to use it in 5 minutes. Git might qualify as best FREE version control system anyone's come up with so far. But best? No, no I don't think so.
- imakesnowflakes 11y ago>Git might qualify as best FREE version control system... No way it is the best. I think Mercurial easily holds the winning position for the version control with most power to weight ratio...
- TheWiseOne3 11y agoYou see 3 hash right. So one would be for my file_1.txt, the other would be for the snapshot created when I commited. What is the third one ? Well because a commit is an object in itself, it is also compressed and stored in the object folder. Wow, after deciphering this kindergarten stream of thought I came to the conclusion that the author's intellect, which I tower above, was vanishingly small just like the collective intellect of "hacker news" itself.
- shubhamjain 11y agoThe most inscrutable part of Git is rebasing and how it works. It took me really long to form a mental model where I can visualise how it does its job. I agree with the author that understanding how Git works is the only way to get comfortable with it. For eg, Rebasing is hard but you will have your "Aha!" moment when you realise that it is nothing but a combination of hard reset and cherry-pick
- cyphar 11y agoI don't understand why most people find the concept of rebasing so alien. Maybe it's because I've never used another VCS, but it's all just very rudimentary graph theory.
- mchahn 11y agoI have read enough of all these tutorials that I understand how git and the git commands work. I could pass a test. But still I have a hard time feeling comfortable enough to spit out commands as needed. I've created a lot of aliases to do common things but that is not the same thing.
- Todd 11y agoA little late, but this really opened my eyes: https://git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Porcelain https://git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Po...
- alblue 11y agoI wrote a series back in 2011 that looked at a bite-sized chunk each week, including how the git repository works, and although the series is long over there is a summar/index page here: http://alblue.bandlem.com/2011/12/git-tip-of-week-finale.html http://alblue.bandlem.com/2011/12/git-tip-of-week-finale.htm... As a meta note; it can be really difficult to keep up a continual blog series. It helped that I advertised it in advance and then wrote around two in advance so that writers block or holidays didn't impact the schedule.
- animeshjain 11y agoThere was a very cool resource (video, ebook) on how git works on a website called peepcode. I just realised they're no longer operational. It was by Scott Chacon I think. Can't find it anywhere else now. Would have made a good addition to the resources listed here.
- fao_ 11y agoIt seems that the old website is availible via archive.org[0], however it was part of a payment system at the time, so archive.org does not store a copy. However, after some digging it turns out that Pluralsight put it under a Creative Commons license, so the git guide I think that you're talking about seems to be availible on Github[1]. [0]: http://web.archive.org/web/20121015074953/https://peepcode.com/products/git-internals-pdf http://web.archive.org/web/20121015074953/https://peepcode.c... [1]: https://github.com/pluralsight/git-internals-pdf https://github.com/pluralsight/git-internals-pdf
- wldlyinaccurate 11y agoIf this kind of approach to learning Git interests you, I took a similar approach with A Hacker's Guide To Git (https://wildlyinaccurate.com/a-hackers-guide-to-git/ https://wildlyinaccurate.com/a-hackers-guide-to-git/). It is much longer and goes into a bit more detail than the OP but (hopefully) is arranged in a way that you can read it a few sections at a time.
- imakesnowflakes 11y agoThe best way to understand Git is to learn Mercurial. It teaches you the things that matters with none of the useless implementation bullshit. If you start with git, you won't have a clue where the interface ends and the implementation details starts. Which is why, I think, people find git hard. I still hope that the whole development world will come to their senses and start using Mercurial more and more...
- a2-47 11y agohttp://pcottle.github.io/learnGitBranching/ http://pcottle.github.io/learnGitBranching/ This one really helped me in the beginning. Visualisation in general helps when learning git (branching, rebasing etc). Ungit is my goto when I want to just see how it (repo) looks like.
- rolfvandekrol 11y agoThe article claims to be aimed a beginners: "There are a lot of posts out there about learning the basic commands of git, this is not one of them. What I’m going to try here is a different approach." The article rings a lot of bells because I actually do understand how Git works. I'm not so sure it is understandable by someone who is new to git. The second sentence of the actual tutorial part: "When you create a git repo, using git init". I'm sorry, what is a repository? Some sentences later: "Here is what’s your .git will look like before your first commit:". What is a commit exactly? I once read another tutorial, which I can't find now. It reads as a story of a group of people exchanging files and in order to avoid administrative mess, eventually end up inventing the core of git, because it solves their problems. I think that tutorial is much better for explaining the concepts of git to beginners. Edit: I think this is the tutorial i mentioned: http://tom.preston-werner.com/2009/05/19/the-git-parable.html http://tom.preston-werner.com/2009/05/19/the-git-parable.htm...
- ithinkso 11y agoOne can be new to git but familiar with i.e. SVN or with VCS theory in general. Sometimes I really do hate it when I'm trying to learn how to use a new tool and every beginner's tutorial starts with explaining how computers work or with some story that is somewhat relevant.
- crispyambulance 11y agoThat's a perfectly fine parable that, except for the distributed part and some vocabulary, could describe _ANY_ modern version control system not just git. THe problem with git is not that it can't do those things, but that it is hard to attain mastery of git commands even if you know what version control is supposed to do.
- ricardolopes 11y agoThat's unfortunately the problem with most tutorials: they just assume you have all the required knowledge. It's hard to make good learning material.
- obelisk_ 11y agoWhen I was still quite new to git, I attended a presentation based on The Git Parable. I found it to be an enlightening talk and it helped me understand git better than what I had until then.
- Kaotique 11y agoThe CLI is a complete mystery and that makes it hard to explain to people. Most of the commands and arguments differ so much that it makes little sense. Delete a branch, commit or tag in a similar way; the commands to do this are totally different. How Git works can be easily drawn out on paper to explain it to someone. The branches, commits and merges is simple to draw. When we lose sense of our state we always take a piece of paper and draw it out. Most of the time you can just figure it out what's up.
- matt4077 11y agoYeah, I used to race through svn workflows without a second thought. With svn, I still don't understand how to (just one example) throw away all the local changes. (No, not git reset --hard. At least that didn't work when I last tried). It came to the point where I thought about spending a week just learning git to defend my berd creds. Instead, I just use a gui for anything beyond add/comit/push. I still don't like not to understand one of my daily tools, but I have real work to do.
- barrkel 11y agoI found I had to build a whole parallel patch management system to rationally deal with svn. Applying the same patch in multiple branches was a royal PITA in svn; in git, it's trivial. git status will tell you how to throw away local changes, btw. Depending on the kinds of changes (e.g. edit/delete added, staged or not) need different commands.
- novel 11y agoBeware, once you learn some of the git useful patterns and features, most likely you'll start feeling very uncomfortable when you have to go back to svn ;)
- dawkins 11y agoinfo/exclude you can put the files you don’t want git to deal with in your .gitignore file. Since .gitignore is committed itself this is very useful.
- NicoJuicy 11y agoMy entire git workflow is based on these tutorials (don't seem to need much else): https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching... and http://nvie.com/posts/a-successful-git-branching-model/ http://nvie.com/posts/a-successful-git-branching-model/ Anyone knows what would be most usefull outside the scope of the tutorials above?
- peterfoldi 11y agoAnd this is my favourite tutorial so far: https://www.youtube.com/watch?v=ZDR433b0HJY https://www.youtube.com/watch?v=ZDR433b0HJY I think it explains everything in 80 minutes.
- peterfoldi 11y agoToo late to edit. I meant this one: https://www.youtube.com/watch?v=xbLVvrb2-fY https://www.youtube.com/watch?v=xbLVvrb2-fY