How to have different branches in different folders in git?

branch, git, git-branch, version-control

Solution

You may like git-worktree. This allows you to checkout different branches to different directories.

E.g.

git checkout master
git worktree add ../dev dev

Problem

I have recently created a repository. I made two branches in it, `master` and `dev`. Now when I copy files in the repositry's directory then the files are added to both the branches. But I only want to add files to `dev` branch and then after the work is done in `dev` then I will copy contents from `dev`'s folder into `master's` folder. Unfortuanately both the branches are thought of as the same folder by git. So how to have different branches in different folders in git?

Original source

Related problems