19 votes

Best, favorite, and/or interestingly-different resources to learn (or re-learn) Git?

Pretty much, the title.

I have been coding professionally for over 2 decades, been using Git for almost as long ... and to this day, it still feels alien and uncomfortable to use. I keep feeling like I am relearning it all over again. I would really like to find some kind of different resource that helps me to make Git "stick" in my brain, and become more intuitive. Maybe that's just not possible, but I keep hoping.

Meanwhile, my roommate is just starting her journey into programming, and her class just started teaching Git ... and I'm eavesdropping a bit, and they're teaching it okay, but I'm sure there are better tutorials out there for a newcomer.

I am aware of -- and currently reading my way through -- both this recent tildes post and the various tutorials mentioned in it. But I am looking for other recommendations, as well ... and I bet I'm not the only one.

Thanx in advance.

14 comments

  1. spit-evil-olive-tips
    Link
    the Peepcode Git Internals ebook is what made Git click for me, when I first read it more than 10 years ago. in particular, follow along with its explanation of Git's data model - blobs, trees,...

    the Peepcode Git Internals ebook is what made Git click for me, when I first read it more than 10 years ago.

    in particular, follow along with its explanation of Git's data model - blobs, trees, and commits - and how they interact. pay close attention to what parts of the data model are immutable and which are mutable. read it until "a branch is just a pointer to a commit" makes sense.

    the biggest stumbling block I've seen in people learning git is that they try to memorize commands (or worse, actions in whatever GUI they're using) that will bail them out of some problem. if they're in situation X, run command A to fix it; in situation Y, run command B.

    instead, for any "problem" in git (detached HEAD being one of the more famous ones), think of what it represents in the underlying data model, and what changes you'd need to make in order to get out of it. from there, figure out the commands you need to run to make those changes.

    (this is, I think, at the heart of why Git is so hard to learn for many people, especially people new to programming or without a grounding in CS fundamentals - Git was written by a kernel developer, for other kernel developers, so it tends to assume a base level of data structures knowledge)

    10 votes
  2. [3]
    NobleDusk
    Link
    I always recommend this website. It’s interactive and you learn using the shell commands, IMO much better than just reading some docs.

    I always recommend this website. It’s interactive and you learn using the shell commands, IMO much better than just reading some docs.

    6 votes
    1. PetitPrince
      Link Parent
      I second this recommendation (Learn Git Branching). The visual representation of both the tree and where the HEAD pointer really help I'm understanding what happens and how to update yoyrbinternal...

      I second this recommendation (Learn Git Branching). The visual representation of both the tree and where the HEAD pointer really help I'm understanding what happens and how to update yoyrbinternal model.

      4 votes
    2. amb1ance
      Link Parent
      Same website I used to start learning how to use git in my intern a couple years ago! It's a great hands-on way to get acclimated to cli in general too

      Same website I used to start learning how to use git in my intern a couple years ago! It's a great hands-on way to get acclimated to cli in general too

  3. [3]
    Maxi
    Link
    This may be controversial, but over the past few months I've become more comfortable using Git, simply by using it with the help of ChatGPT. Rather than going through the torture of reading the...

    This may be controversial, but over the past few months I've become more comfortable using Git, simply by using it with the help of ChatGPT.

    Rather than going through the torture of reading the documentation or the myriad of sites with cryptic diagrams (sometimes animated) and DAG theory and trying to memorize the various commands, I present my git problem du jour to ChatGPT and ask it what commands I should try, ChatGPT often also includes a nice helpful description of what is going on.

    I've also made a few complicated aliases I use often, and through that excersize learnd about the --format command:

    Chronological stashes
    List of stashes, one line each with the stash ID, relative timestamp, and last commit message. Colour coded.

    git stash list --pretty=format:"%C(yellow)%<(14)%gd%C(reset) %C(auto)%cr%C(reset) %C(auto,blue)%gs%C(reset) %C(auto,dim white)%d%C(reset)"
    

    Chronological branches
    Shows all branches in chronological order with the branch with the latest commit first. Displays 2 lines per branch with branch name, human readable commit time (14 hours ago), hash. Line prepended by * on the current branch . Second line is indented and contains last commit message and commit author.

    Note: whitespace is important in the below command

    git branch --sort=-committerdate --format="%(HEAD) %(color:yellow)%(refname:short)%(color:reset) %(color:green)%(committerdate:relative)%(color:reset) %(color:red)%(objectname:short)%(color:reset)
        %(color:blue)%(subject)%(color:reset) | %(color:magenta)%(authorname)%(color:reset)"
    

    Simple log
    One-line git log showing commit has, date, author name, message. Colour coded

    git log --pretty=format:"%C(yellow)%h %C(green)%ad %C(blue)%an%C(reset)%d %C(reset)%s" --decorate --date=short
    
    4 votes
    1. [2]
      Comment deleted by author
      Link Parent
      1. Maxi
        Link Parent
        Yep, ChatGPT is best used for asking for things you can verify yourself. If you can't verify it's output, then it's not that safe to use. Thanks for those aliases! They look helpful!

        So long as you're mindful of ChatGPT occasionally lying, sure. Just gotta be on guard, don't trust it completely, and don't become a blind regurgitator of what it spits out. If anything, it's a good way to figure out what you really want to research in the documentation.

        Yep, ChatGPT is best used for asking for things you can verify yourself. If you can't verify it's output, then it's not that safe to use.

        Thanks for those aliases! They look helpful!

        1 vote
    2. elcuello
      Link Parent
      Well ChatGPT is kind of Google on steroids and back when Googling became popular for all kinds of problems people had the same concerns. As long as you consider your answers critically I don't see...

      Well ChatGPT is kind of Google on steroids and back when Googling became popular for all kinds of problems people had the same concerns. As long as you consider your answers critically I don't see why this should be a problem.

  4. IJustMadeThis
    Link
    Git really started to click for me when I learned the git-flow branching methodology. I’d also highly recommend a client like GitKraken; visualizing the branches really helps, plus it has git-flow...

    Git really started to click for me when I learned the git-flow branching methodology. I’d also highly recommend a client like GitKraken; visualizing the branches really helps, plus it has git-flow built in if you choose to use it, and helps a lot with git’s more complex features like cherry pick.

    Is there a specific aspect of git that doesn’t stick for you? Remote/local, push/pull, branching, stashing, etc?

    2 votes
  5. compsciwizkid
    Link
    I've seen a handful of tutorials and interactive sites, but as someone who seems to always possess a bit more git knowledge than my coworkers... I am quite sure that the best ways I've learned...

    I've seen a handful of tutorials and interactive sites, but as someone who seems to always possess a bit more git knowledge than my coworkers... I am quite sure that the best ways I've learned over the years were: solving real problems, and having a mentor to show me parts of git I hadn't seen before.

    A tutorial can teach you the basics, but I consider a handful of techniques to solidly classify someone as intermediate - techniques that polish your commits on branches before/during/after PRs. I was trained a bit on interactive rebase, git add -p (tons of power in all the options this presents), etc. Curiosity helped me a lot, whenever I had an idea for how I could clean up my branch a bit (e.g. move a change from one commit to a different one, extract a set of changes into a new commit) I would explore on my own, screw up my commits horribly, figure out how to fix it, or ask for help.

    I haven't met many people that'd I'd classify as advanced users of git or experts. But I think the distinguishing factor here is fixing really bad mistakes. Using the reflog, tracking how a rebase went sideways, etc. I have jumped onto calls with teammates who were ready to give up cause they had tried everything. But git is really quite amazing, you can figure out what was done to get into a bad state, and with experience you can decipher what that user was trying to do. Then you can teach how to accomplish that.

    Hopefully you work on a team with good communication. Having others that are interested in taking their git skills to the next level would be very beneficial for you, I think.

    Hope that helps.

    2 votes
  6. kwyjibo
    Link
    Julia Evans has a zine on git that's pretty good and certainly different.

    Julia Evans has a zine on git that's pretty good and certainly different.

    2 votes
  7. [4]
    dave1234
    Link
    Thinking outside the box... try using a Git GUI if you haven't already. You might find it a lot more intuitive than the Git command line, even if you enjoy using the command line in general. I've...

    Thinking outside the box... try using a Git GUI if you haven't already. You might find it a lot more intuitive than the Git command line, even if you enjoy using the command line in general.

    I've used a Git GUI ever since I started using Git around 2011. I have a pretty strong understanding of how Git works - certainly better than my coworkers. But I never bothered learning the Git command line and I don't care to.

    I mostly used TortoiseGit in the past, which is an absolute powerhouse. It'll do nearly anything you could want to do via the command line, except that it hides the stage feature. It's FOSS, but only supports Windows.

    These days I use GitKraken, which is proprietary, supports far fewer features than TortoiseGit, and is slower. But I like it better than every other Git GUI I've tried, and it runs on Linux, MacOS, and Windows, so that makes it worth the money to me. I run Linux at home and Windows at work, so it's useful to have one GUI for both.

    1 vote
    1. [3]
      glad_cat
      Link Parent
      I also confirm using a GUI is a great way to learn git. You can visualize the branches, the "pointers" (aka branches or stashes), etc., you can rebase and move stuff and see the results visually....

      I also confirm using a GUI is a great way to learn git. You can visualize the branches, the "pointers" (aka branches or stashes), etc., you can rebase and move stuff and see the results visually. It's also, IMHO, way faster than reading a tutorial about the command-line version.

      As for the clients, I don't recommend GitKraken as it's loosely based on Visual Studio Code and it's buggy as hell. The only interesting feature is the integration with GitHub or GitLab but I never used it. Sometimes it cannot commit, sometimes it freezes and you have to kill it.

      I prefer Sublime Merge or SmartGit which are more simple and more stable.

      1 vote
      1. [2]
        dave1234
        Link Parent
        I don't have any real complaints about GitKraken except that it's slow - due to using Electron, I guess. I haven't encountered any commit issues or freezes. It's been good enough for me to pay for...

        I don't have any real complaints about GitKraken except that it's slow - due to using Electron, I guess. I haven't encountered any commit issues or freezes. It's been good enough for me to pay for it out of my own pocket.

        Two of my favourite features of GitKraken are profiles and workspaces.

        Each profile has its own GitKraken settings, third party integrations (GitHub, etc.), and open tabs. I work for a company that does work for multiple clients, and profiles make it really easy to switch between each each one.

        Each workspace is a collection of related Git repositories, plus integration with an issue tracker (e.g. JIRA) and Git host (e.g. GitHub). I can have a separate workspace for each product, and fill them with its components (individual repositories). It makes it easier to switch between them.

        I explored Sublime Merge a while back, but I remember it feeling pretty basic. Maybe it's time I gave it another look.

        1. glad_cat
          Link Parent
          There is no need to use it again for you I guess because it is indeed very basic and that's why I love it, but for your usage it wouldn't be interesting.

          I explored Sublime Merge a while back, but I remember it feeling pretty basic

          There is no need to use it again for you I guess because it is indeed very basic and that's why I love it, but for your usage it wouldn't be interesting.

          1 vote