Optimize Git Workflow with Worktrees for Developers

If you are a developer, I hope that this helps you ! I've faced a issue quite sometimes when you are working on a feature, and someone just comes up with an urgent modification to production or bug fix. Usually I'm used to stashing my work, or doing a commit that I would over-ride later with an amend commit, but that makes me have to see if I stashed or commited my changes, finding the right stash if I stashed more times than one, or checking if I have to amend. Another thing thing that I noticed sometimes where I had to debug an issue, and I would be comparing a good state commit with a bad state commit, checking out into them, running the server, and comparing what has changed using a debugger. This was pretty tiresome, since if you don't find the issue right away, you had to switch multiple times, and build and run the server if there's no hot-reload (My backend in go didn't have those), and then compare. I should have just cloned the repo again, and run on another port to compare, but this old thing in git that I found is much better. While creating a design for a new project I'm working on, I came across git worktrees, and noticed that I can use them in my regular workflow as well. Just need to add a worktree, and it makes a copy of my code for local running, that I can host on another port, which allows me to run the 2 servers side by side to debug them up. Also, I just create a worktree if someone disturbs me to switch context, and then later am able to return to what I was working on. This is something that you might be able to also use when you have a monorepo, and need to run different versions for different microservices. Do explore it, it's a nice ignored feature in git. You'll be hooked. #Git #WebDev #SoftwareEngineering #CodingTips #Programming #DeveloperExperience #DX #ProductivityHacks #CleanCode #WorkflowOptimization #GitWorktree #DevTools

To view or add a comment, sign in

Explore content categories