Git Worktrees and Neovim: A Match Made in Coding Heaven

preview_player
Показать описание
Git Worktree is somewhat of a niche feature in Git that too few developers know about. It allows you to change branches and contexts without ever having to stash your changes or commit and reset.
However, it can be quite the hassle when not maintained well and having to work with the CLI.
In this video I'll go through the best practices including a sweet Neovim plugin that makes the experience silky smooth!

LINKS AND TOOLS MENTIONED

MY FAVOURITE GEAR
* If you enjoy my content, using the links below will help me with a small commission, so thank you!

CONSIDER SUPPORTING THIS CHANNEL

MY KEY LINKS

#neovim #productivity #git #devops #ops #dev #terminal #CLI #system #sysadmin #cloud #ricing #linux #macos #commandline #typing #keyboard #tutorial #beginner
Рекомендации по теме
Комментарии
Автор

This is so subtle that not knowing it gets the job done but knowing this makes it so fun and easy on head to do the job.
Thanks buddy got to learn something new.

niksingh
Автор

WOW. I've always taken the "clone another copy" approach. At one point, at a previous job, I had 10 cloned copies and trying to remember which branch had what was getting very difficult. This bare+worktree approach looks amazing!

mulchman
Автор

Amazing video! I always appreciate the quality and clarity of how you explain things! I'm definitely going to give this a shot.

cantucodes
Автор

DevOps toolbox: a place where you learn to cook code and write coffee : )

pwnwriter
Автор

Great overview. Been meaning to try changing my workflow to use Git worktrees and this helps me understand it a lot better. Thanks!

ascourter
Автор

Thanks for the video. For me what has worked best for me till now is the combination of tmux and git worktree.

ilyeshammadi
Автор

Your videos are always so nice ! Thank you once again

elythh
Автор

Thank you so much for this! So useful.
I always found it pretty strange how git managed the issue of storing modified files by stashing. Didn't know about worktree until now, and it does seem like a much saner way to handle it.

ravihlb
Автор

That's awesome! I have been using worktrees for a year or so now too, it's a game changer.

I found that using the bare repo is not very nice though. I remember having to manually change refs and whatnot, so these days what I do is:

git checkout $(git commit-tree $(git hash-object -t tree /dev/null) < /dev/null)


This will create a new empty root commit and checks it out. So what you'll have is just a .git folder, and it works like you'd expect a regular non-bare repository. Plus you don't get to see all of those bare repository files :) I then do as you did in the video, create the new worktrees under this folder.

Guilherme-qkso
Автор

Thanks so much for this video! I will definitely try to incorporate this into my config. The workflow looks really promising.
I'll also be that guy: what recipe are you using for the coffee? I struggle to make nice-tasting small cups, and too much caffeine can ruin my day.

eclbg
Автор

damn that some good looking coffee. Oh and git worktrees seem cool too!

typecraft_dev
Автор

Amazing content as always. Please consider putting your coffee gear in video description too ☕

Автор

Thank you sir I learned something new today.

sarojregmi
Автор

I was so focused on the coffee making technique, I missed the first few minutes and had to restart.

RetroPaul
Автор

Great video! Your workflow looks really efficient. Have you done a video about it?

Also, how do worktrees treat generated files? Say worktree A and B differ in contents of files in the foo directory, such that when you build foo, the generated foo/bin should be different. If you run build in worktree A from directory foo and it generates foo/bin and you run build in worktree B in foo as well and it generates foo/bin -- is the git worktrees workflow able to maintain both sets of generated files?

joseville
Автор

Your coffee routine is mesmerizing. heh heh now I want coffee!

qwarlock
Автор

The only issue is when there are important gitignored files like a .env that I want to share across all branches. With that approach, I'd either have to copy it over everywhere or symlink it, both option add complexity

yanisfourel
Автор

Does Intellij IDEA (or any similar Java IDE) work with this concept of git worktrees? Working in a JVM project the "normal way" requires a lot of complex class loading stuff. Imagine shifting to the git worktree model. That might be a nightmare for IDE developers to implement right.

Автор

what if i want to run each worktree's should i do npm install on each worktree's or can i create a common file

AntonyXavier-vj
Автор

How do you open 2 different branches side by side, if I try this, it always takes the current buffer's place. I tried '<C-v>' as this is telescopes option to vertical split the file.

Edit: I created the split first and could then open the other branch with telescope, is this the way?

iceke