DEV Community

Louiza Mak
Louiza Mak

Posted on

I watched "So You Think You Know Git" so you don't have to

Throughout my coding career so far, I've really only used a few git commands. My most frequent, can be found in the code block below.

git init
git pull
git clone
git add
git commit
git push
git log
Enter fullscreen mode Exit fullscreen mode

And on occasion, I'll pull out a git rebase if I have to do something fancy or to fix a nerve-wracking mistake. So, I've made it my mission to get much more familiar with git and how git branches work when it comes to larger repos this month. It's also my first Hacktober so this is really more for me than it is for you. But if you're here and you're interested in what I have to say, than more power to you. I invite your curiosity and hope you can learn something new or brush up on an old fact lost over the years.

I recently watched Scott Chacon's FOSDEM 2024 talk, "So You Think You Know Git". He's one of the co-founders of GitHub, co-author of "Pro Git", and co-creator of Git Butler. The video was from 8 months ago, but in case it slipped your radar like it did mine, here are some personal highlights. I definitely encourage anyone reading to watch the full video, but if you're short on time, I've got you covered.

Conditional Configs

A fantastic feature of GitHub that allows you to work on personal or company projects with easy and flexibility. includeIf will allow you to assign what .gitconfig file is used for specific directories, letting you manage multiple git identities.

Two linkedif lines of code

Scott Chacon - FOSDEM 2024

Oldies But Goodies

Scott covers a few notable time-saving git commands that have been around for quite some time.

git maintenance

This command adds a cron job for git to run every hour and perform maintenance tasks on your repository. Since this is running in the background, it speeds up other git commands since they do not have to tack the processes onto other git commands and run as an afterthought. This helps to optimize git repository data.

--force-with-lease

git push --force-with-lease is recommended over git push --force as it is much safer. The command will check if someone has already pushed changes to the branch you're working on and will only allow your push if the branch has not diverged. If the branch has already changed, the push will be rejected which ensures that you will not accidentally overwrite someone else's work. This adds a layer of safety when you're working in collaborative environments.

Big Repo Changes

After Microsoft bought GitHub, many implementations were made to benefit monorepos or large repositories. The goal was to make working in with these large repositories faster and more streamlined.

prefetching

Similar to git maintenance, every hour the system will fetch references from the server for the project you're working on. It will not update references until the command git fetch is ran, but it makes this process faster because the data was already prefetched.)

partial cloning

Allows users to filter out blobs, an object type used to store contents of each file in a repo, and only fetch what you need. This makes the repo act almost like a file system, increasing the speed. One con of this feature is that it does not work with git blame.

commit-graph write

This command caches an index of all the commit objects so that it can do commit graph operations very fast. It is essentially a pre-computed graph that represents a commit history in a more efficient way because the larger a repo, the slower commit graph walks will be. This is because git needs to traverse through each commit to be able to answer any questions such as git log or git blame.

GitButler

The last section of Scott's talk was about his current project, GitButler, a git client that allows you to work on simultaneous branches. It utilizes a drag and drop feature that quickly organizes file changes to separate virtual branches. There also seems to be intuitive branch management features and could make working on multiple PR requests that much easier.

I have not personally used it, but I think it's right up my alley and can ensure that I don't make any extra commits to ongoing PR's for my Hacktober. I'll have to give it a try!

Scott Chacon at FOSDEM 2024

Scott Cachon - FOSDEM 2024

Conclusion

Scott covers a few more topics in his video and goes further in depth with these commands, old and new. He also provides some stellar visual examples throughout the PowerPoint presentation. I found his talk entertaining and his "shotgun" style kept topics to the point. It also made me realize there is so much more to learn about Git than I had anticipated. Scott mentioned how there are about 145 git commands, 82 of which is relevant currently. And that is much more than I use in my Git toolbelt.

I'll have follow-up git-based blogs in the near future as I continue researching and learning more!

Top comments (0)