Git's Best And Most Unknown Feature
Key Takeaways
The video discusses Git's work trees feature, demonstrating its capabilities and the speaker's workflow with vim, and showcasing tools like getworktree and telescope for worktree management and automation.
Full Transcript
so get work trees are incredible if you haven't used them oh my goodness they fixed so many things that are wrong with my current git workflow so before i tell you what git work trees are i thought it would be better if we talk about why you should use get work trees first have you ever checked out a project started working on and then need to pivot right you either have a message from a co-worker go look at this bug something's down in production i'm my fault on production by the way or you need to just work on something else so you know you've had to pivot right so what do you do well you have to go and stash your current tree or you commit right there with a little message please squash me later and then you forget about doing it and your co-workers are like wtf with us so what is this squash message you got here this is not even that good and you have to do this you have to check out something else you have to do some work and then you have to like uncheck out and go back and then unstash or look at your commit and try to remember what you're doing right it's just it's just like not that great right it's just like not a fun experience so work trees allow you to have multiple commits checked out at the exact same time each folder will represent a different commit meaning that you can have master you can have your feature one you can have feature two you can have your production issue that you accidentally did again sorry about production so if that does not sound incredible you haven't been used to get that long because this is mind-blowing and the best part is is that this feature has been around for a while it's just nobody's ever really heard of it even guido just discovered these yeah they're incredible so what are git work trees well they allow you to have multiple commits checked out at the exact same time as opposed to a traditional cloning of a repo you have one commit checked out plus any changes you've made so let me just show you what that means so let's go like this git clone this repo you'll notice that all i'm doing is doing a simple clone and when i go in there you'll notice that i'm on the master branch i can go get branch dash a you can see all the branches if i do any changes i'll have to either stash them or commit them to be able to change branches so let's rm rdf that get work tree right away and let's do a get clone bear now bears the keywords you need to use here and then go get work tree dot and vim there we go so now we're gonna clone in a bear repository now if you remember last time i had lua colon w that's pretty much it inside of my repo so now let's go back into git worktree and what you'll see this time is a bunch of different stuff now this is obviously all the information required to be able to use a bear repo so what you're going to do instead now is tell the bear repo what commit you would like to have checked out so i'll go like this get work tree add master this will add master at its latest known commit i can also add other ones get work tree add readme right okay i can get at let's see get work tree add foo bar a bass so now i have three separate work trees checked out let's re-ls now notice the difference between this one and this one i have readme i have master and i have fubar bass if i were to go into foobar baz it would be fubar bass at its commit and whatever changes i have if i were to jump into vim you'll notice that i'll be able to see all the different stuff that is to do with this plugin if i were to make some sort of change right here i could then come back out and cd back into say the master folder and that exact same change would not be there at all so that means i could have separate checkouts in their own state hopefully at this point you see the power of get work trees and you are excited you can also remove them obviously get work tree remove and then you can name any of the ones that you want to remove i don't know why just to auto complete it like that let's just remove foo bar bass there we go we removed it oh i already have some changes in it you have to do it with four so get work tree remove let's not have the huge gigantic path this time foobar baz and force there we go if we re-look at our list of items you'll notice that foo barbaz is gone so when i saw this i immediately just i just fell in love i fell in love i i knew for that moment that get work trees were gonna be in my future thoroughly i've been in the process of changing over all of my work projects into bare checkouts and actually doing work trees as opposed to whatever the nonsense i have been using i can't even remember at this point it seemed so arcane and distant so at this point i didn't want to have to write all these commands cd around open and close vim do all that so i wrote a quick plugin called get worktree that wraps all those get operations and does some convenient updating for you i got a status line to make it easier to tell what branch i'm in so i don't actually edit the wrong code and we created a telescope plugin to make worktree operations easier all right so we're back inside of the get work tree and so now i'm going to create a branch using the plugin at this point i don't have any key maps or anything so i'm just raw typing it in and just simply creating a work branch on both sides you'll notice that after i got done executing it what happened right here so you should notice right away that something changed right i'm no longer in that root directory i'm actually moved into other branch you'll see right away that my status line has now let me know that i'm doing that and of course telescope has updated to work with this new repo so i just got done showing you how to create it using the raw command but this time i'm going to use telescope to be able to switch branches to make it even easier so let's switch back to master you'll notice that something did change notice that this branch says master as opposed to other branch two what just happened there well let me make it a little bit easier let me move my cursor down and then re-switch back so what just happened well we actually swapped out the file so that you're editing the same file but in the new work tree on top of that if you happen to have a file that doesn't exist doesn't exist right there we go if we have something right here and we decide to swap back to master so if i jump back and go back to master it'll actually just put me back in x that way i'm looking at it i know something has changed it put me back in x because that file did not exist in master combining the three plugins i showed you allowed me to have a pretty fast workflow right there i can easily do the worktree operations using telescope to help guide me on top of that i can tell where i'm at because the status line and lastly those operations are provided by the getwork3 plugin so at work i have a large c plus application that does have sub modules in it if i forget to get some module update when i create a branch it will fail the configure stage and often i don't recognize that it did and then i end up spending five ten minutes trying to figure out what the heck is going on i'm not the most observant i get it so part of the get worktree plugin allows you to hook into changes in your work tree so here you go here's a simple example of me using plenary to create a job and work for you to tap into changes now notice that i can just simply do entry change the operation can either be create switch or delete and when i see that there is a creation and it's the netflix television device repository i am going to go and execute get some module update in that repository so that way i just don't even ever have to think about it again it just happens for me and i am none the wiser right this is something that just saves a lot of time and headaches because every time i create a new tree i have to do it anyways why not just let it be done for me and i don't have to think about it karen do you think that we could force everyone to use work trees you can't okay well if i'm the boss here at the startup why can't i osha osha doesn't oh wow i i had no idea that osha had rules even for this hey thank you for watching please check out worktrees they will make your life a thousand times better because you still get all the standard usages of git you can just commit push pull whatever inside of each branch but each branch is its own folder and thus works very simple hopefully you like that little plug-in that i showed you the integration with telescope is incredible and combining it with a status line would really help you kind of know where you're at everything is linked down below please let me know if you've used get work trees what you thought about it if you have any tips for me i will take them let me know down below everything's made live on twitch and of course our discord is filled with thousands of people at this point my name is the primetime thank you for watching
Original Description
HOW HAVE I NOT HEARD OF GIT WORK TREES??? WHAT THE EFF. They are so incredible. You have to check them out!!! In this video I go over them briefly, assuming you are smart enough to understand them, and also show you my workflow with vim! Its fantastic!
### Links
Linode: https://linode.com/prime
Discord: https://discord.gg/3ujcVMe
Twitch: https://twitch.tv/ThePrimeagen
Insta: https://instagram.com/ThePrimeagen
Twitter: https://twitter.com/ThePrimeagen
VimRC & i3: https://github.com/ThePrimeagen/.dotfiles
Keyboard (15% off, I don't earn commission): https://bit.ly/primeagen-adv2
Keyboard: https://ohkeycaps.com/products/theprimeagen-dactyl?aff=2 (PRIMEDACTYL $25 off)
#vim #linux #git
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from ThePrimeagen · ThePrimeagen · 2 of 60
1
▶
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Two Simple Steps to go from IDE to Vim
ThePrimeagen
Git's Best And Most Unknown Feature
ThePrimeagen
My Developer Workflow - How I use i3, tmux, and vim
ThePrimeagen
Github Copilot MAKES A CLI GAME IN GOLANG FROM SCRATCH?!?!
ThePrimeagen
I made the greatest tool ever! | tmux & cht.sh & fzf
ThePrimeagen
Is TypeScript (NodeJS) Faster than Go?? | A server comparison
ThePrimeagen
How to make TypeScript Blazingly Fast (JavaScript/NodeJS)
ThePrimeagen
Learn Vim in Less than 2 Minutes
ThePrimeagen
The biggest lie about programming? REACTING to tech twitter
ThePrimeagen
Rust or Go for my next project? WHAT TO CHOOSE? (as a senior intern engineer)
ThePrimeagen
Go is faster than Rust??! Go vs Rust vs TypeScript Servers (as a scientist)
ThePrimeagen
You only Git Merge?!? feat Theo : DevHour #1
ThePrimeagen
YOU DONT UNIT TEST??? DevHour #1 Theo
ThePrimeagen
Tech TikTok - Is this really programming? | React
ThePrimeagen
I am dying
ThePrimeagen
Comparing Rust (Yew) vs TypeScript (React) NodeJS | SSR times
ThePrimeagen
Why I use Vim in 2022
ThePrimeagen
How programming feels
ThePrimeagen
Why I Quit Netflix
ThePrimeagen
Programming on TikTok
ThePrimeagen
If I could give advice to myself when starting as a software engineer
ThePrimeagen
How am I suppose to get a job as a software engineer?
ThePrimeagen
Why do I feel burnt out? (software engineering)
ThePrimeagen
I am done with vim
ThePrimeagen
Maintaining Motivation as a Software Engineer
ThePrimeagen
Bun (TypeScript) is faster than Rust!?!
ThePrimeagen
Go is blazingly faster than Zig?
ThePrimeagen
Facebook Recommends Rust?
ThePrimeagen
5 Things I Hate About JavaScript
ThePrimeagen
Why I Make Content
ThePrimeagen
Is ADHD Bad For Programming?
ThePrimeagen
Vim As You Editor - Advanced Motions P1
ThePrimeagen
How I Would Get My First Job If I Started Over
ThePrimeagen
Vim as your editor - Advanced Motions P2
ThePrimeagen
My Best Decision Professionally
ThePrimeagen
Should you use RUST as your FIRST programming language?
ThePrimeagen
How I Made JavaScript BLAZINGLY FAST
ThePrimeagen
Is JSON Blazingly Fast or...?
ThePrimeagen
Vim As Your Editor - Introduction
ThePrimeagen
Vim As Your Editor - Horizontal
ThePrimeagen
Astro IS SO GOOD
ThePrimeagen
STOP LYING, The truth about Software Engineering
ThePrimeagen
Does Your Editor Matter?
ThePrimeagen
React Is This Fast???
ThePrimeagen
Vim As Your Editor - Vertical Movements
ThePrimeagen
Rust for TypeScript devs : Borrow Checker
ThePrimeagen
Will ChatGPT Terminate Your Job?
ThePrimeagen
0 to LSP : Neovim RC From Scratch
ThePrimeagen
From Meth To Netflix
ThePrimeagen
Faster than your favorite JS framework?
ThePrimeagen
Primeagen Answers the Webs Most Asked Questions for a Software Engineer
ThePrimeagen
This Algorithm is 1,606,240% FASTER
ThePrimeagen
Looking Under the Hood of JavaScript
ThePrimeagen
What Next...Finding a New Job In Software
ThePrimeagen
JSON, I hardly know 'er
ThePrimeagen
RUST Enums ARE Better
ThePrimeagen
CoPilot Review: My Thoughts After 6 Months
ThePrimeagen
How to Vim in 2023: Tips and Tricks
ThePrimeagen
Twitter's Algorithm Has MASSIVE Problems
ThePrimeagen
Rust Foundation IS DOING WHAT????
ThePrimeagen
More on: Tool Use & Function Calling
View skill →Related Reads
📰
📰
📰
📰
Your AI audit tool is a lead generator, not a final verdict
Dev.to · Jeremy Burgos
10 AI Image Prompts Every Content Creator Can Use for Urdu/English Quotes
Medium · Machine Learning
The Best AI Course Generator in 2026? I Tested 7 to Find Out.
Dev.to AI
Automate Spotify and YouTube Playlists - Chapter 2: Setting Up Spotify
Dev.to · Tawanda Nyahuye
🎓
Tutor Explanation
DeepCamp AI