Git's Best And Most Unknown Feature

preview_player
Показать описание
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

#vim #linux #git
Рекомендации по теме
Комментарии
Автор

Honestly, when I watch Linux related videos (git, vim, window managers, core utils, configurations, Emacs) I feel like prehistoric cave-man who somehow got on the alien's spaceship. Sometimes I can even understand how things work

fanone
Автор

I have actually been using this feature for years as a deployment mechanism to deploy different states of the code to different folders that are mapped to different sites, to test different behaviours side by side in test/integration environments 😅

plankguitars
Автор

Cool feature - thanks for sharing

I would mention that you actually don't need the "git clone --bare <repo>" you can just name your "master" clone accordingly eg

git clone ${repo} ${repo}-master
cd ${repo}-master

And then for each branch you want to work on in a worktree

git worktree add ../${repo}-${branchname} #<-- note the "../" infront of the name

And then you'll have 2 normal working checkouts in separat directories that are just each branch and you can just switch project/work dir in your IDE of choice.

Also if you forget to add the "../" when adding a worktree to the "master" checkout resulting in a new directory that isn't committed, then there is "git worktree move <dir> <new-dir>" command to move it accordingly.

BjarkeBruun
Автор

You should create series how to use git ;)

flsh
Автор

Pretty cool feature. I don't think I'll integrate into my workflow because git stash works for 99% of my use cases (I'm not often being asked to change directions in the same project), but good to have the knowledge about worktrees if I'm ever asked to change it up and do more work on a singular project.

mattpeterson
Автор

Hey!
I recently got into all these sweet tools and I started git recently, but I only use it to have a trace of all the changes I do on important projects.
I love the way you talk and present things! I'd love to see you present a way to work with git and explaining its tools.
About what you said to another comment: that people will say there is a better way ect... you can say that : this is my way of doings things, I don't say it's the best, I just present mine so people that are new can see the possibilities. You're not being a teacher, you're still presenting stuff :D
Thank you for your content !!!!
Cheers from France

mfyoutube
Автор

Cool to see that even the Primeagen gets files like ":w" sometimes :)

TimPushman
Автор

Interesting, I just never had this problem you pitch at the start. I rarely even stash, stashes are too easy to forget about. If I have to check out a different branch while having uncommitted changes, I just do a WIP commit with a meaningful name that will be sitting right there when I get back. It's to be amended later. On the remote, there is a push rule that rejects any commits that start with WIP. So these WIP commits are self-descriptive, you don't forget them and you can't push them by accident.

As for the worktree, I feel like having a bunch of different folders with uncommitted and unnamed changes hanging around would create more problems than it would solve.

hosmanadam
Автор

It’s been 2 years… still the best thing since sliced bread?!

In all seriousness, a two year later retrospective would be great!

spottedmahn
Автор

What I do when I need a separate workspace is to simply create another folder and clone from the other local folder which was already cloned. I can then push and pull from the origin which is simply the other folder. I can name the remote whatever I want and do this with multiple folders to isolate my work and make it easy to move commits between them.

offwhitemke
Автор

You blew my mind in the first minute. This is game changing. Thanks prime! <3

Westar.
Автор

How the hell did I not know about this? Awesome walkthrough. Thanks!

maclarel
Автор

Ohh my I just woke up and this is what I watched
I have been searching for a proper way to do this forever
Man you are a life saviour @ThePrimeagen

rishushrivastav
Автор

BRUH. This is going to make the work at my day job much easier. Legit AF

BryanJenks
Автор

I would have some issue with JS projects needing to have a humongous node_modules folder under each worktree directory, but I can see this being super useful for other types of projects where I'm jumping back and forth between branches constantly to test changes or find differences. It can be really useful to have two IDE windows open with a different branch in each, and I used to just clone to another directory. No more!

garfieldnate
Автор

I like worktrees, but one of the downsides is support. Often when some tool has git support, it doesn't tend to have worktree support :(.

therealsunnyk
Автор

Holy cow I am excited....you know how I was doing this? I was checking out multiple copies of the repo...what a AM FRICKEN STOKED!

batboy
Автор

I just downloaded your worktree plugin, my life is forever changed now! Thank you so much for making my life easier!

fastandfidler
Автор

Did he touched his mouse o.O
This is not the content for what I am subscribed for!
:' D Keep going man, love it

Skylla
Автор

Oh boy...every year I have 4-5 of those "huh, I need to adopt this right now" moment. This is definitely one of those, thanks for explaining Git worktree !

Jubijub