Can I check out a git branch without removing other orphaned branches from my local files?

40 views Asked by At

I have two related projects that are in separate branches of the same git repo (master and demo). When I check out the master branch, it removes the files in my demo folder from my local hard drive, and vice versa with the demo branch checked out. Is it possible to avoid this behavior?

2

There are 2 answers

0
axelrod On

For any local GIT repository, there can be up to one working directory at a given time. For that reason, the files in the 'folder' (working dir) are replaced when you switch branches. A possible workaround i'm sometimes using (assuming you have a remote repository from which you've cloned the local one) is create another local repository pointing to the same remote repository (= create another folder in your computer and clone the same repository). Now, in one repo checkout master, in the second one checkout demo, and you can work on both branches in parallel.

0
Ôrel On

you can create a third branch where you merge your two branches.