DEV Community

Cover image for "Git" more than one branch
Kyle Parisi
Kyle Parisi

Posted on

7 2

"Git" more than one branch

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!

Top comments (2)

Collapse
 
itsasine profile image
ItsASine (Kayla)

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.

Collapse
 
pkristiancz profile image
Patrik Kristian

your *
:P

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up