How to use Docker with git worktree

Viewed 318

I recently started using git worktree and it is awesome. However, I am not sure how to make it work with Docker. Here is my flow:

  1. repo-a has a dockerFile to build a local container.

  2. I create a new worktree like git worktree add branch-a this will create a folder named branch-a with branch branch-a.

  3. I received a PR to review and I need to switch to branch-b. So I go back to my --bare clone repo and I do git worktree add branch-b. and cd into that folder.

  4. My docker container doesn't catch new files because it is still linked to files on branch-a and if I do docker-compose up -d on branch-b, it throws an error saying that The container name "/<name here>" is already in use by container "31344e3448df72e032c42a96d078ea57c11a75023d197e9ab0683e7c773f54e4"

How can I make my docker container to listen to changes on a different folder?

Thanks

1 Answers

Perhaps a simple way to do this is to have a symlink from the directory Docker expects the files to be. And the symlink points to the actual directories of the different branches. You update the symlink each time you need to work on one of the different worktree branches.

Related