"Git" more than one branch

twitter logo github logo ・1 min read

At a previous job I had to review my coworkers code and continue developing a feature. For that I used to just checkout a whole new clone of the project in a review/ folder. From there I could safely review the code locally.

Now I'm working on a large rewrite. This time I need to review how the current system operates. Here is an alternative way to do that:

# git worktree add <path> [<branch>]
git worktree add legacy develop

If you cd to legacy, your git commands will be in the context of that branch. A nice pro-tip to keep in your back pocket!

twitter logo DISCUSS (2)
markdown guide
 

I like worktrees for writing tests for one branch while tests are running in the "main" branch (full suite of integration tests, so about an hour of runtime). But I end up defaulting to just having 1 active branch and using gitlab's MR diff view for reviews.

 
Classic DEV Post from Jun 2

Stay Healthy as a Developer

Kyle Parisi profile image
Working on https://buildapart.io, https://fluxion.app in my spare time.

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️