I have two copies of same git repository locally. Those two copies have each their own local branches. Can I somehow "unify" those two repositories and create one which will have local branches from both of repositories?
Unify branches of two local copies of same repository
471 Views Asked by Wakan Tanka AtThere are 2 best solutions below

Although usually used to reference a central server like GitHub, git's "remote" concept can actually link any two repositories, including two directories on your local computer.
So if you have a copy at /srv/foo and one at /srv/bar, you could fetch all the branches from one into the other like this:
cd /srv/foo
git remote add bar /srv/bar
git fetch bar
This will then bring them in as "remote tracking branches", so a branch on the "bar" copy called "feature-42" will be accessible as "bar/feature-42". That will still be there when if you delete /srv/bar, like a branch from GitHub would still be accessible if you had no internet access.
To turn them into actual local branches, i e. access them without the "bar/" prefix, you could just check out each in turn, e.g. git switch feature-42
The solution is quite simple:
Edit
We are going to work only with 2 repo for simplicity...