Git Worktrees and Neovim: A Match Made in Coding Heaven

Поделиться
HTML-код
  • Опубликовано: 27 дек 2024

Комментарии • 87

  • @niksingh710
    @niksingh710 Год назад +8

    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.

  • @cantucodes
    @cantucodes Год назад +8

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

    • @devopstoolbox
      @devopstoolbox  Год назад +1

      Thank you my man! Thanks for the feedback it means a lot!

  • @ascourter
    @ascourter Год назад +3

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

  • @pwnwriter
    @pwnwriter Год назад +20

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

  • @mulchman
    @mulchman 5 месяцев назад +1

    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!

  • @ilyeshammadi7278
    @ilyeshammadi7278 Год назад +1

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

    • @devopstoolbox
      @devopstoolbox  Год назад

      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

  • @joseville
    @joseville 5 месяцев назад +1

    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?

    • @devopstoolbox
      @devopstoolbox  5 месяцев назад +1

      @@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

    • @joseville
      @joseville 5 месяцев назад

      @@devopstoolbox Thanks for info! Will check out your workflow vid!

  • @iceke18
    @iceke18 Год назад +1

    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?

    • @devopstoolbox
      @devopstoolbox  Год назад +1

      Yes, this is the straightforward way, unless you’d like to create it directly which you can map if you really insist

  • @AntonyXavier-v9j
    @AntonyXavier-v9j 9 месяцев назад +1

    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

    • @devopstoolbox
      @devopstoolbox  9 месяцев назад

      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

  • @typecraft_dev
    @typecraft_dev Год назад +3

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

  • @ravihlb
    @ravihlb Год назад

    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.

  • @elythh
    @elythh Год назад +1

    Your videos are always so nice ! Thank you once again

  •  Год назад +1

    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.

    • @devopstoolbox
      @devopstoolbox  Год назад +1

      Hmmm I haven’t been working with anything that isn’t Vim for over 6 years so I can’t really say… sorry

  • @TayTayChan
    @TayTayChan Год назад +1

    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?

    • @devopstoolbox
      @devopstoolbox  Год назад +1

      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)

    • @TayTayChan
      @TayTayChan Год назад +1

      ​@@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

  • @5ihdi
    @5ihdi Год назад

    Which plugin you use to have this 3:27 command line mode as floating window?

  • @yanisfourel
    @yanisfourel 9 месяцев назад +1

    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

  •  Год назад

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

  • @eclbg
    @eclbg Год назад +1

    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.

    • @devopstoolbox
      @devopstoolbox  Год назад +2

      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!

  • @pali122
    @pali122 Год назад +1

    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

    • @devopstoolbox
      @devopstoolbox  Год назад +1

      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 😃

  • @Guilherme-qk9so
    @Guilherme-qk9so Год назад +1

    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.

    • @devopstoolbox
      @devopstoolbox  Год назад +1

      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

    • @Guilherme-qk9so
      @Guilherme-qk9so Год назад +3

      @@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.

    • @S7hadow
      @S7hadow Год назад +2

      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

    • @devopstoolbox
      @devopstoolbox  Год назад

      @@S7hadow cool!

  • @艾曦-e4g
    @艾曦-e4g Год назад +1

    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?

    • @devopstoolbox
      @devopstoolbox  Год назад

      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!

    • @艾曦-e4g
      @艾曦-e4g Год назад

      @@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.

    • @devopstoolbox
      @devopstoolbox  Год назад

      @@艾曦-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

  • @khanriza
    @khanriza 5 месяцев назад

    Tried this plugin today and doesn't seem to work. Anyone else has it working?

    • @devopstoolbox
      @devopstoolbox  5 месяцев назад

      @@khanriza IIRC it’s now moved to a “v2” branch completely rewritten, make sure you use that

    • @alexpan4987
      @alexpan4987 4 месяца назад

      @@devopstoolbox Nope, the latest updated branch is master and it was updated 9 months ago :(

  • @Borgoo
    @Borgoo Год назад

    Great video! What are the plugins for having the commandline/search in a floating window?

  • @canchengwu7477
    @canchengwu7477 Год назад

    Amazing! Do you use kitty terminal ?

  • @tamascsontos3324
    @tamascsontos3324 Год назад

    Why do you do cx instead of cd? What is that tool?

    • @devopstoolbox
      @devopstoolbox  Год назад +1

      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

  • @qwarlock4126
    @qwarlock4126 Год назад

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

  • @sarojregmi200
    @sarojregmi200 Год назад

    Thank you sir I learned something new today.

  • @RetroPaul6502
    @RetroPaul6502 6 месяцев назад

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

    • @devopstoolbox
      @devopstoolbox  6 месяцев назад

      I took these off over time :) maybe I need to put some of it back

  • @thecodealchemist7095
    @thecodealchemist7095 Год назад +1

    I felt i just learnt how to make myself proper coffee

  • @JeremyMoore1
    @JeremyMoore1 Год назад

    This is awesome! Thanks for sharing

  • @Danielo515
    @Danielo515 Год назад

    Sorry, why you changed branches just to stash Changes?

    • @devopstoolbox
      @devopstoolbox  Год назад +1

      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!

  • @HaroldHersey
    @HaroldHersey Год назад

    Love your keyboard.

    • @devopstoolbox
      @devopstoolbox  Год назад

      Thank you! This is the HHKB. It’s been with me for 4 years and I swear it I proves with time 😃

  • @cpplain
    @cpplain Год назад

    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).

    • @devopstoolbox
      @devopstoolbox  Год назад +1

      Interesting! I still prefer the bare option although I understand the motive.

  • @a_maxed_out_handle_of_30_chars
    @a_maxed_out_handle_of_30_chars Год назад +1

    ahh, nice and thank you :)

  • @Tony_Sol
    @Tony_Sol 2 месяца назад

    They'll come up with anything just to avoid using an interactive git rebase

  • @jay_morelli
    @jay_morelli Год назад

    The meme of prime and lex 💚

  • @sayanta.k
    @sayanta.k 2 дня назад

    3:56

  • @rossvold
    @rossvold 9 месяцев назад

    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

    • @devopstoolbox
      @devopstoolbox  9 месяцев назад

      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

    • @rossvold
      @rossvold 9 месяцев назад

      @@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.

    • @rossvold
      @rossvold 9 месяцев назад +1

      @@devopstoolbox usually on other repos it always displays head and merge: origin/branch

    • @devopstoolbox
      @devopstoolbox  9 месяцев назад +1

      @@rossvold interesting. Really not sure what’s going on

    • @rossvold
      @rossvold 9 месяцев назад

      @@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

  • @nasang7478
    @nasang7478 Год назад

    Just found your channel, very awesome, instantly subscribed 🫡