TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: What made you finally grok Git?

53 pointsby Ldorigoover 2 years ago
I've been using it for over 7 years, and while I've memorized a bunch of commands and have some idea of what the commit tree is, I'm perpetually bewildered by some of its messages or the behavior of some commands - and the only way I can fix major trainwrecks is by nuking a branch (when I'm lucky, the entire repository when not) and copy-pasting stuff until it's back to working state.

40 comments

doixover 2 years ago
When I realized it&#x27;s just a DAG and you&#x27;re just manipulating a graph and pointers.<p>Then it just became a matter of mapping git CLI commands to how they manipulate the graph.
评论 #33653554 未加载
评论 #33653664 未加载
评论 #33653547 未加载
评论 #33653601 未加载
评论 #33655777 未加载
评论 #33653652 未加载
politelemonover 2 years ago
I have not grokked git — it hasn&#x27;t been necessary to. Understanding some of the basics, knowing enough of the commands to run, and figuring out which StackOverflow answer applies to my current situation is good enough. If I have to spend too much time knowing its internals and delving into its philosophies, then it is not a useful tool that lets me get on with my tasks.
评论 #33653595 未加载
评论 #33653584 未加载
mcvover 2 years ago
What&#x27;s important to understand about git is that it allows time travel, and time travel enables changing history, and changing history is a really bad idea. Do not ever change the history without knowing what you&#x27;re doing. In git, this means mostly rebasing and other stuff that messes with existing commits.<p>Messing with existing commits can be fine <i>as long as you&#x27;re messing with the only existing version of that commit</i>. Commits that exist in other branches, have been shared with other people, have been pushed to remote, etc, should be left alone. Rebasing local, unpushed single commits in your one working branch is fine. Rebasing anything else will cause problems. If rebase is causing you problems, do not rebase.<p>Also: small commits, short branches, merge often.
评论 #33653552 未加载
评论 #33653567 未加载
jhellanover 2 years ago
This youtube made it click for me what is actually going on:<p>Git for ages 4 and up - <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=1ffBJ4sVUb4" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=1ffBJ4sVUb4</a>
评论 #33654336 未加载
pjmlpover 2 years ago
Nothing, I keep using it as if it was Subversion.<p>With the help of IDE tooling and TortoiseGit, the command line basic stuff for workflows that might not be exposed on the graphic tools.<p>If the repo gets corrupted, I delete it and do a fresh clone.<p>Life is too short to bother going deeper than that.
hdhdxkfchskover 2 years ago
get in the habit of commiting every few lines you write, and before creating a pull-request(tm) use &#x27;git rebase -i&#x27; and cleaning up into meaningfull bit sized history. move related changes togheter, remove (squash) things that didn&#x27;t make it to the end, etc.<p>oh and never join any project that uses github and force squash-commits-on-pullrequest-merge. that is a sign that nobody there knows git or they don&#x27;t care about code history.<p>edit: and yes, some rare times, rebase -i and moving things around will cause local conflicts. do not fear them. resolve and continue. it&#x27;s all code you just wrote, should be easy and is part of the understanding process.
评论 #33653597 未加载
AndrewDuckerover 2 years ago
Git from the bottom up. A very clear and simple guide to the internals.<p><a href="https:&#x2F;&#x2F;jwiegley.github.io&#x2F;git-from-the-bottom-up&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jwiegley.github.io&#x2F;git-from-the-bottom-up&#x2F;</a>
评论 #33654779 未加载
评论 #33668953 未加载
srhtftwover 2 years ago
I remember <i>Git from the inside out</i> and <i>Learn Git Branching</i> were very helpful when I started using git. The <i>Git Command Explorer</i> was good as well. Links from my notes below:<p>Git Command Explorer<p>- <a href="https:&#x2F;&#x2F;gitexplorer.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;gitexplorer.com&#x2F;</a> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=28888763" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=28888763</a><p>Learn Git Branching<p>- <a href="https:&#x2F;&#x2F;learngitbranching.js.org" rel="nofollow">https:&#x2F;&#x2F;learngitbranching.js.org</a> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=18504948" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=18504948</a><p>Git from the inside out<p>- <a href="https:&#x2F;&#x2F;codewords.recurse.com&#x2F;issues&#x2F;two&#x2F;git-from-the-inside-out" rel="nofollow">https:&#x2F;&#x2F;codewords.recurse.com&#x2F;issues&#x2F;two&#x2F;git-from-the-inside...</a> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9272249" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9272249</a>
auxymover 2 years ago
For me it was reading about git internals:<p><a href="https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2&#x2F;Git-Internals-Plumbing-and-Porcelain" rel="nofollow">https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2&#x2F;Git-Internals-Plumbing-and-Po...</a><p>It made me understand how simple git really it under the hood, you just need to understand how the commands operate on this simple data structure.
kazinatorover 2 years ago
I don&#x27;t think I&#x27;ve fully grokked git, but<p>1. There is a similarity with Lisp. A commit is an object with a pointer to the next one (or multiple parents). These objects are garbage collected. Heads point to commits: they are like root pointers. These pointers are mutating. When a new commit is made, it&#x27;s a lot like a new cons cell pushed onto a list in Lisp: (push new-commit HEAD). (Stupidly, git history isn&#x27;t terminated by the equivalent of NIL; yet some git operations require a parent. There are ugly workarounds.)<p>2. Key insight: commits store snapshots, not deltas. Diffs are calculated.<p>I&#x27;ve <i>slightly</i> delved into the internals.<p>1. I developed a procedure for reordering commits on a branch with zero conflicts, using tree objects directly, without any rebase workflow. So that is to say, we peel back the brandch, and then create commits using the tree objects of the original commits, in whatever order we want. Because git is based on snapshots, there are no conflicts: it&#x27;s not a rebase operation on cherry picks.<p>2. I went through an exercise once of manually creating a stash entry, by creating the right objects and editing some text files in .git
aibover 2 years ago
Being the go-to git guy for a whole project when everyone was new to it.<p>Are you using it from the command line? I feel that helps a lot. Get a good log alias[1] and get hacking. I almost exclusively use the official CLI, with the exception of git-gui for committing and rolling back patches (lines &#x2F; hunks). (I find it&#x27;s easier than `add -p` and that CTRL+J is a good time saver.)<p>1: As an example, <a href="https:&#x2F;&#x2F;github.com&#x2F;aib&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;.gitconfig#L29" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;aib&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;.gitconfig#L29</a>
rapjr9over 2 years ago
&gt;What made you finally grok Git?<p>When I realized what it was designed for. It was designed for one or a few people to shepherd software contributions from many people, pushing most of the work out to the masses and making the job of the shepherds easier. So it is designed kind of backwards of what you&#x27;d want for a personal project or a small team. Software integration is one of the most difficult tasks in software engineering and it requires someone who is aware of how everything operates and fits together and what the overall design is. If you use Git in a team where everyone does their own integration there is a strong likelyhood that no one actually does integration, which makes things go haywire later (when it is difficult to back out). If you don&#x27;t have the resources to put someone in charge of integration (it can take a lot of time) do not use Git. Just use a good source control system and do design and integration in meetings up front (and periodically thereafter).<p>In some sense I think Git is inefficient since it doesn&#x27;t so much guide development as reject bad code. All that rejected code is wasted time that could have been used more productively with better guidance. Yet the centralized nature of control in Git makes it look like development is being guided. If the center of control is not also doing design, integration, and guidance though it creates a lot of wasted effort and failed projects. To a large extent this is true of any method of software development, but I think using Git can make it worse because it can make it easier for sub-teams to ignore integration until it is too late. Git is not magic. Getting your code to build and run is not the same as integration.
jamil7over 2 years ago
Sit down with a coffee, read the book <a href="https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2" rel="nofollow">https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2</a> and just spend the time learning how to use it. You&#x27;ll save yourself a bunch of time and headache and won&#x27;t need to be nuking repos or branches any more. There&#x27;s a lot it can do, so a big part is finding out what fits into you and your team&#x27;s workflow.
blopover 2 years ago
It was all magic to me until one day I finally took the time to look at git internals.<p>You can build a valid git repo with simple unix shell commands, and that really helped me to understand the magic behind the git commands:<p><a href="https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2&#x2F;Git-Internals-Git-Objects" rel="nofollow">https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2&#x2F;Git-Internals-Git-Objects</a>
beermonsterover 2 years ago
Reading this[1] and getting the data structures&#x2F;mental model correctly internalised in my head.<p>Although I do use git from the cli (or magit) primarily, this knowledge has helped me pick-up front end tools intuitively and have helped others when I&#x27;ve never used their preferred tool. All of this doesn&#x27;t seem possible unless you&#x27;ve put in the effort learning what&#x27;s going on behind the scenes. That is to say, git itself it neither user friendly nor intuitive it must be learned.<p>Knowing mercurial (hg) beforehand did slow my learning progress a bit with all the false-friends. You may find it easier to learn if you don&#x27;t have to re-learn some naming.<p>[1] <a href="https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2" rel="nofollow">https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2</a>
评论 #33653604 未加载
112233over 2 years ago
It&#x27;s super easy to understand how git works — I&#x27;m doing it several times per month.<p>Seriously, low-level git, while not familiar to most devs, is logical and consistent. It&#x27;s the UI level that is total disaster. Don&#x27;t worry, you will forget everything in a week.
fn1over 2 years ago
Using GitUp on the Mac as a client. It allows you to select a commit and press Options-S to reset your branch to this commit, it allows you to squash etc.<p>And best of all it keeps a backup of your entire repository so you can undo whatever git command you just did.
karmakazeover 2 years ago
Maybe the one thing that made it click for me was realizing that a branch is merely a label to a git commit hash. There can be local and remote ones and the local is aware of the remote (e.g. git pull). Checking out a branch makes it current, with filesystem matching the branch head&#x27;s git fileset state. New commits get added and the branch label moved to the new head.<p>That and a git tree view GUI or &quot;git log --oneline --graph&quot; and &quot;git reflog&quot; to undo stuff. Also, you&#x27;re better off committing temp stuff on the current local branch with message &quot;WIP&quot; than using &quot;git stash&quot;.
评论 #33664071 未加载
wildcowover 2 years ago
This made it click for me: <a href="https:&#x2F;&#x2F;codewords.recurse.com&#x2F;issues&#x2F;two&#x2F;git-from-the-inside-out" rel="nofollow">https:&#x2F;&#x2F;codewords.recurse.com&#x2F;issues&#x2F;two&#x2F;git-from-the-inside...</a>
rgoulterover 2 years ago
This took me from &quot;add&#x2F;commit&#x2F;push, and pull&quot; to being able to do rebases: <a href="https:&#x2F;&#x2F;learngitbranching.js.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;learngitbranching.js.org&#x2F;</a>
评论 #33653616 未加载
评论 #33653590 未加载
mrkeenover 2 years ago
When I realised it was all about share-xor-mutate, just like all reasonable systems:<p>Rebase and force-push on your own branches only (they are mutations), pull-request when putting stuff onto other branches.<p>I also find the whole git tree WAY easier to read if it&#x27;s fast-forward-only, and no merge commits.<p>Atlassian&#x27;s not as popular as they used to be I guess, but I found Bitbucket presents the best view of the git tree ever. When I wanted to do anything advanced, I&#x27;d look at the Bitbucket view, do local git commands in my shell, push, and then watch Bitbucket again.
ecnahc515over 2 years ago
Using rebase and reflog really taught me a lot about git, because it &quot;rewrites&quot; history and exposes you to some nuance. Like: basically nothing in git is ever gone if it was at one point committed to the repository, that includes branches you delete and never pushed, it also includes commits that are removed with git reset --hard. Once I learned about how to find references, refer to them, and manipulate them, everything else made a lot more sense.
he_is_legendover 2 years ago
The trick(s) to git is not using `git add -A`, and being diligent (as in checking before you commit) about the changes that you are committing. Only add and commit what is relevant to the task that you are working on. But it&#x27;s even simpler than that. Before you commit anything, check what you are about to commit. Is it what you expected? Is it relevant? Does it work? Has it been tested? Is it likely to pass a code review?
评论 #33653788 未加载
评论 #33653661 未加载
orzigover 2 years ago
Make a sandbox repository and just break it repeatedly. Within the realm of basic commands, I bet you already know how to do most things (including recovering from small mistakes), but it feels too scary so you revert to non-– GIT methods. In a sandbox, you can get the reps in without any fear.<p>You could then graduate to forking a real repo. Again experiment fearlessly, with slightly more realistic scenarios.
Aprecheover 2 years ago
I started using it around 2008 on the recommendation of a co-worker. I already had a lot of experience with RCS, CVS, and SVN. I understood the problems and frustrations caused by those tools, because I suffered with them for years. After reading the Git documentation I immediately understood how Git solved those problems. Then I just started using it exclusively. The end.
etermover 2 years ago
This altassian article: <a href="https:&#x2F;&#x2F;www.atlassian.com&#x2F;git&#x2F;tutorials&#x2F;merging-vs-rebasing" rel="nofollow">https:&#x2F;&#x2F;www.atlassian.com&#x2F;git&#x2F;tutorials&#x2F;merging-vs-rebasing</a><p>In particular the golden rule of never rebasing a public branch has served me very well and I never seem to run into the &quot;merge hell&quot; that others complain of.
dzhiurgisover 2 years ago
As a beginner - each of stash, branch, staged and remote is just a swimlane, kinda like illustration here: <a href="https:&#x2F;&#x2F;nvie.com&#x2F;posts&#x2F;a-successful-git-branching-model&#x2F;" rel="nofollow">https:&#x2F;&#x2F;nvie.com&#x2F;posts&#x2F;a-successful-git-branching-model&#x2F;</a> but can&#x27;t remember where did I read it initially
avipover 2 years ago
0. mental model: staging, local, remote. c&#x27;est tout<p>1. `git status` + gitk before and after git commands<p>2. guess upfront what the result of git commands will be (in terms of gitk &#x2F; git status)<p>3. be fluent with commit, push, pull, checkout, reset, merge, and possibly rebase (I call it required but it&#x27;s opinionated) - you can safely ignore the other git api in 96% of workflow
milliamsover 2 years ago
The Git Parable (<a href="https:&#x2F;&#x2F;tom.preston-werner.com&#x2F;2009&#x2F;05&#x2F;19&#x2F;the-git-parable.html" rel="nofollow">https:&#x2F;&#x2F;tom.preston-werner.com&#x2F;2009&#x2F;05&#x2F;19&#x2F;the-git-parable.ht...</a>) cliched it for me.
mvdwoordover 2 years ago
Introduction to Git with Scott Chacon of GitHub - This was really helpful for me.<p><a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=ZDR433b0HJY" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=ZDR433b0HJY</a>
jfzoidover 2 years ago
this video where he explains Git&#x27;s dag with tinkertoys <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=3m7BgIvC-uQ" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=3m7BgIvC-uQ</a>
gus_massaover 2 years ago
TortoiseGit for Windows and Git Cola for Linux. I use the command line very seldom, only for very weird things (like moving commit from a repo to another repo, but in a different internal folder).
mshekowover 2 years ago
Teaching Git to others (e.g. company-internal workshops). You learn so much from teaching, and also from questions others ask, helping you discover your unknown knows and unknown unknowns.
lkschubert8over 2 years ago
Playing through this game <a href="https:&#x2F;&#x2F;learngitbranching.js.org" rel="nofollow">https:&#x2F;&#x2F;learngitbranching.js.org</a>
skirmishover 2 years ago
Having a window of &quot;gitk --all&quot; always open on my repo and refreshing the view makes it really obvious what my commands are doing.
furstenheimover 2 years ago
Treat commits as immutable data. Don&#x27;t try to amend, squash or rebase.<p>Having one commit merges is overrated
solardevover 2 years ago
I just use an IDE (Jetbrains) with a git GUI built in and stop worrying about how it works
readonthegoappover 2 years ago
don&#x27;t get it yet, but learning &#x2F; realizing that it can remote into other machines and execute commands (via SSH&#x2F;server, so no other server software - like an HTTP server - is necessary) was definitely eye-opening.
iExploderover 2 years ago
git is fine, one just needs to learn how to use it properly.<p>one has yet to witness the abomination that is svn, sourcesafe, or &quot;software working on my machine&quot; delivered by a zip file in order repent and mend ones ways
coutegoover 2 years ago
Implementing it.<p>Once I read somewhere it is just a key - object, append only, DB then it seemed easy to implement the core of it, so I did. It&#x27;s simpler that it sounds.
评论 #33659869 未加载