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.
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!
Yep, I know worktree is loved by many. To me, this is still going out of the IDE (even if to a floating pane) and feels like using any external software, where as fugitive is still at the tip of my fingers
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 you can find my workflow and entire setup in a very recent video! Re worktrees - if I’d ask whether something would work in a branch and the answer is yes, then it’s the same for worktrees
How do you open 2 different branches side by side, if I try this, it always takes the current buffer's place. I tried '' 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?
Good question. Like other things it depends because it would make sense to use the same ones for every branch. That said, I’d symlink to a central one and run npm i again to make sure I’ve got the right ones
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.
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.
Hey, I saw prime's workflow on this too, but decided not to use it because I sometimes need to work in node projects. Each directory needs to have the node_modules folder and always reinstalling dependencies is slow and takes up a lot of space. Have you encountered similar issues in your workflow? If so, how do you cope with it?
Yep! Should be rather easy holding the shared dir on the bare repo and then symlinking all the child branches to ../node_modules. Id even add a script / keybinding to your tooling, depends on what you use to manage the trees (Neovim, CLI / other)
@@devopstoolbox I did think of that, but admittedly I was too lazy/busy to try it out 😅 I'll give it a serious go this time, because you did complete the picture of the worktrees workflow
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
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.
Hi! Of course! I’m using the James Hoffman one cup V60 method: 15gr beans to 250 water: Pour off the boil water and wait 45s, add 50ml, on 1:10 add 50ml, at 1:30 add 50ml, at 1:50 add last 50ml. Pour gently and in round motions. It’s a lot about the distribution and even-ness of pouring. And the taste has a lot to do with water temperature and of course the right grind size! Good luck!
I have been using it too, but is not really that different from clonning a repo twice and having two different active branches, at the end is mostly the same thing just with git commands
Yeah I think I even mentioned it at some point in the video. However, it’s not quite the same in the way you organize your code and the ability to switch between them. Moving up and down for tree is not the same as working on multiple running got branches at the same time! And, if you have more than 1 repo, like 10+ it quickly becomes unmanageable. So I stopping working with more clones and just stashed my code constantly. So happy I don’t have to anymore 😃
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.
Firstly- very cool solution! But, what is it exactly that makes you change refs, or why? I’ve been doing that for a month or so and still haven’t had any issues. Maybe I haven’t encountered enough edge cases 🤷 The bare repo only serves as a parent dir, each tree holds its .git and I find it works like an entirely different clone
@@devopstoolbox I don't recall what the problem was exactly, it was a very long time ago. I got it when trying to either pull or push from a remote. I remember researching and finding that, since a bare repo is not supposed to be doing one of those, you needed to run update the remote refs to point to the correct place, or something like that.
I’m also using bare repos with the .git folder. To achieve that while cloning you can do ‘git clone -bare /.git’. The small downside is that you have to manually set the folder name, but then you have a clean directory for your work trees
It is amazing! I love your videos. I have two problems to ask for help. 1. How to fetch and update the new branch from the remote, I found it is difficult for me to get the newer updates from a different branch. 2. How would you diff the same file in different branches using this kind of setup?
Thanks for the kind words :) To your questions : 1. Not sure what you mean by that - are you asking how to integrate changes from another branch to your current one? As in - `git merge` ? Or just some commits by `git cherry-pick` ? Something along those lines? BTW, 99% of my git commands are done using fugitive (I have a video about that as well), the rest I run either directly from command line or command line through neovim (`:!git something`) 2. This video is about worktrees, for diffs I use `gvdiffsplit `. Another tool you might wanna check out is github.com/so-fancy/diff-so-fancy. It's not my cup of tea but many people swear by it!
@@devopstoolbox sorry for the fusion I made. I try to make it more clear. 1. I used similar tools and setups. I clone the repo barely and then I add a new worktree. At this time, if the remote repo had a update on different branch or new branch, how to get them in the current worktree (or branch). 2. Since you open the same file in different branches (directories) in one neovim instance, how to diff them more easily? gvdiffsplit will work on this setup? I don't know how to achieve that using fugitive in neovim. Thanks a lot.
@@艾曦-e4g Hey! So, re 1. just go to the worktree you're using, in which case you'll be running in a .git repo where you can then pull changes! 2. I think regardless of the structure being worktrees, you can keep working with gdiffsplit because at the end of the day these are git branches :) even though they are structured differently locally. Please to tell me if this helps! If not we'll get to the bottom of it
Good catch! I use a tool called exa replacing “ls” for me (colorful output, built in tree and more - you can see it in my terminal setup video), so I have “cx” mapped to cd && exa with a few flags so that I cd but also get a list of files with the info I want (got status etc) you can checkout my dotfiles to see. If you don’t find it LMK I’ll send the exact alias
No! They replace each other 😉 I started the video showing what I *used to do* - stashing and checking out another branch. Once you work with gittrees it is completely unnecessary!
I like using worktrees but not with bare repos. My solution is to create a worktrees directory in my project directory (../ from repo), add a sym link to the worktrees directory in the repo), and git ignore the link. Not perfect, though I find this better than dealing with bare repo caveats (e.g., working with remotes).
Does git fugitive work when withing a worktree in a --bare repo? I can use the interface to stage and commit, but once i have committed it dissapears and i have to use my cli to push to where i want. @devopstoolbox
Yes of course! I’m using it all the time. How did you switch trees? Is there a chance you’ve actually started nvim from the bare repo path and then switched tree with a plugin? Maybe fugitive then doesn’t see the tree but the bare source
@@devopstoolbox what i did: clone a bare repo. then git tree add "lastmod" . Then i cd into lastmod, open nvim and change a file Fugitive shows unstaged and staged stuff, and lets me hit cc and make a commit. once i have hit commit it just vanishes. if i run git log from there, i can see the commit and that head is at the lates spot, it's just that it's not letting me push from the interface. Not entirely sure what's going on there.
@@devopstoolbox did the troubleshooting and i figured that apparently 'If the upstream is not setup correctly when trying to pull or push, make sure the following command returns what is shown below. This seems to happen with the gitHub cli.' This for some reason seems to fix it
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.
Yes! Exactly 😃
Amazing video! I always appreciate the quality and clarity of how you explain things! I'm definitely going to give this a shot.
Thank you my man! Thanks for the feedback it means a lot!
Great overview. Been meaning to try changing my workflow to use Git worktrees and this helps me understand it a lot better. Thanks!
DevOps toolbox: a place where you learn to cook code and write coffee : )
Love this! Stealing 😉
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 100%!!!
Thanks for the video. For me what has worked best for me till now is the combination of tmux and git worktree.
Yep, I know worktree is loved by many. To me, this is still going out of the IDE (even if to a floating pane) and feels like using any external software, where as fugitive is still at the tip of my fingers
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 you can find my workflow and entire setup in a very recent video!
Re worktrees - if I’d ask whether something would work in a branch and the answer is yes, then it’s the same for worktrees
@@devopstoolbox Thanks for info! Will check out your workflow vid!
How do you open 2 different branches side by side, if I try this, it always takes the current buffer's place. I tried '' 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?
Yes, this is the straightforward way, unless you’d like to create it directly which you can map if you really insist
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
Good question. Like other things it depends because it would make sense to use the same ones for every branch.
That said, I’d symlink to a central one and run npm i again to make sure I’ve got the right ones
damn that some good looking coffee. Oh and git worktrees seem cool too!
😂 Thank you!!
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.
Your videos are always so nice ! Thank you once again
Thank YOU 😉
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.
Hmmm I haven’t been working with anything that isn’t Vim for over 6 years so I can’t really say… sorry
Hey, I saw prime's workflow on this too, but decided not to use it because I sometimes need to work in node projects. Each directory needs to have the node_modules folder and always reinstalling dependencies is slow and takes up a lot of space. Have you encountered similar issues in your workflow? If so, how do you cope with it?
Yep! Should be rather easy holding the shared dir on the bare repo and then symlinking all the child branches to ../node_modules. Id even add a script / keybinding to your tooling, depends on what you use to manage the trees (Neovim, CLI / other)
@@devopstoolbox
I did think of that, but admittedly I was too lazy/busy to try it out 😅
I'll give it a serious go this time, because you did complete the picture of the worktrees workflow
Which plugin you use to have this 3:27 command line mode as floating window?
This is “noice.nvim”!
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
True. I use symlinks
Amazing content as always. Please consider putting your coffee gear in video description too ☕
Great idea!!
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.
Hi! Of course! I’m using the James Hoffman one cup V60 method:
15gr beans to 250 water:
Pour off the boil water and wait 45s, add 50ml, on 1:10 add 50ml, at 1:30 add 50ml, at 1:50 add last 50ml.
Pour gently and in round motions. It’s a lot about the distribution and even-ness of pouring.
And the taste has a lot to do with water temperature and of course the right grind size! Good luck!
I have been using it too, but is not really that different from clonning a repo twice and having two different active branches, at the end is mostly the same thing just with git commands
Yeah I think I even mentioned it at some point in the video. However, it’s not quite the same in the way you organize your code and the ability to switch between them. Moving up and down for tree is not the same as working on multiple running got branches at the same time!
And, if you have more than 1 repo, like 10+ it quickly becomes unmanageable. So I stopping working with more clones and just stashed my code constantly. So happy I don’t have to anymore 😃
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.
Firstly- very cool solution!
But, what is it exactly that makes you change refs, or why? I’ve been doing that for a month or so and still haven’t had any issues. Maybe I haven’t encountered enough edge cases 🤷
The bare repo only serves as a parent dir, each tree holds its .git and I find it works like an entirely different clone
@@devopstoolbox I don't recall what the problem was exactly, it was a very long time ago. I got it when trying to either pull or push from a remote.
I remember researching and finding that, since a bare repo is not supposed to be doing one of those, you needed to run update the remote refs to point to the correct place, or something like that.
I’m also using bare repos with the .git folder. To achieve that while cloning you can do ‘git clone -bare /.git’. The small downside is that you have to manually set the folder name, but then you have a clean directory for your work trees
@@S7hadow cool!
It is amazing! I love your videos. I have two problems to ask for help. 1. How to fetch and update the new branch from the remote, I found it is difficult for me to get the newer updates from a different branch. 2. How would you diff the same file in different branches using this kind of setup?
Thanks for the kind words :)
To your questions :
1. Not sure what you mean by that - are you asking how to integrate changes from another branch to your current one? As in - `git merge` ? Or just some commits by `git cherry-pick` ? Something along those lines?
BTW, 99% of my git commands are done using fugitive (I have a video about that as well), the rest I run either directly from command line or command line through neovim (`:!git something`)
2. This video is about worktrees, for diffs I use `gvdiffsplit `. Another tool you might wanna check out is github.com/so-fancy/diff-so-fancy. It's not my cup of tea but many people swear by it!
@@devopstoolbox sorry for the fusion I made. I try to make it more clear. 1. I used similar tools and setups. I clone the repo barely and then I add a new worktree. At this time, if the remote repo had a update on different branch or new branch, how to get them in the current worktree (or branch). 2. Since you open the same file in different branches (directories) in one neovim instance, how to diff them more easily? gvdiffsplit will work on this setup? I don't know how to achieve that using fugitive in neovim. Thanks a lot.
@@艾曦-e4g Hey!
So, re 1. just go to the worktree you're using, in which case you'll be running in a .git repo where you can then pull changes!
2. I think regardless of the structure being worktrees, you can keep working with gdiffsplit because at the end of the day these are git branches :) even though they are structured differently locally.
Please to tell me if this helps! If not we'll get to the bottom of it
Tried this plugin today and doesn't seem to work. Anyone else has it working?
@@khanriza IIRC it’s now moved to a “v2” branch completely rewritten, make sure you use that
@@devopstoolbox Nope, the latest updated branch is master and it was updated 9 months ago :(
Great video! What are the plugins for having the commandline/search in a floating window?
Thanks! Checkout nvim “Noice”!
Amazing! Do you use kitty terminal ?
Nope :) Wezterm ATM
Why do you do cx instead of cd? What is that tool?
Good catch!
I use a tool called exa replacing “ls” for me (colorful output, built in tree and more - you can see it in my terminal setup video), so I have “cx” mapped to cd && exa with a few flags so that I cd but also get a list of files with the info I want (got status etc) you can checkout my dotfiles to see. If you don’t find it LMK I’ll send the exact alias
Your coffee routine is mesmerizing. heh heh now I want coffee!
Thank you sir I learned something new today.
🙏🏽
I was so focused on the coffee making technique, I missed the first few minutes and had to restart.
I took these off over time :) maybe I need to put some of it back
I felt i just learnt how to make myself proper coffee
Here to help 😉
This is awesome! Thanks for sharing
Sorry, why you changed branches just to stash Changes?
No! They replace each other 😉
I started the video showing what I *used to do* - stashing and checking out another branch. Once you work with gittrees it is completely unnecessary!
Love your keyboard.
Thank you! This is the HHKB. It’s been with me for 4 years and I swear it I proves with time 😃
I like using worktrees but not with bare repos. My solution is to create a worktrees directory in my project directory (../ from repo), add a sym link to the worktrees directory in the repo), and git ignore the link. Not perfect, though I find this better than dealing with bare repo caveats (e.g., working with remotes).
Interesting! I still prefer the bare option although I understand the motive.
ahh, nice and thank you :)
They'll come up with anything just to avoid using an interactive git rebase
The meme of prime and lex 💚
3:56
Does git fugitive work when withing a worktree in a --bare repo?
I can use the interface to stage and commit, but once i have committed it dissapears and i have to use my cli to push to where i want.
@devopstoolbox
Yes of course! I’m using it all the time.
How did you switch trees? Is there a chance you’ve actually started nvim from the bare repo path and then switched tree with a plugin? Maybe fugitive then doesn’t see the tree but the bare source
@@devopstoolbox what i did: clone a bare repo. then git tree add "lastmod" .
Then i cd into lastmod, open nvim and change a file
Fugitive shows unstaged and staged stuff, and lets me hit cc and make a commit.
once i have hit commit it just vanishes.
if i run git log from there, i can see the commit and that head is at the lates spot, it's just that it's not letting me push from the interface. Not entirely sure what's going on there.
@@devopstoolbox usually on other repos it always displays head and merge: origin/branch
@@rossvold interesting. Really not sure what’s going on
@@devopstoolbox did the troubleshooting and i figured that apparently 'If the upstream is not setup correctly when trying to pull or push, make sure the following command returns what is shown below. This seems to happen with the gitHub cli.'
This for some reason seems to fix it
Just found your channel, very awesome, instantly subscribed 🫡
Thank you sir!