gitgithub

Second checkout of the same local Git branch?


Is it possible to have a more than one checkout of the same local branch, in the same way you can checkout a remote branch?

  1. Checked out a remote repo
  2. Branched locally
  3. Committed some changes locally to my new branch

Now I need a second folder that is an exact copy of my branch without the build artifacts. Ideally I would check it out again.

I don't want to push to remote, since my branches are just experiments. My understanding is that the local git repo just covers one folder (where it is located), so it is not possible.


Solution

  • Is it possible to have a more than one checkout of the same local branch

    No you cant. Use the git worktree add and create a second copy of your workspace with any desired branch without the need to perform clone

    git worktree add <new_path>/<branch>
    

    then checkout any branch in the new location (but it cannoe be the same branch!!!!)

    If you wish to checkout the same branch you will need to clone it again to a new location