Is there a way to sync different directories to different branches in the same project/repo in Git?

48 views Asked by At

I have two version of a website that I ideally would like to sync with an existing Git repo. They are in two different physical directories on my local machine.

Is there a way I can add the contents of one folder to one branch and the other to a different branch?

1

There are 1 answers

0
David Deutsch On

To do this, set up a git repository in both directories with git init. Then, create a different branch in each directory with git checkout -b branch-name. Put whatever filespecs you wish into .gitignore in both directories, then git add the appropriate files in each directory. Finally, add the same remote in both directories with git remote. git push them both, and you will have a single repository with two branches, with two local directories, one mapped to each branch.

Note that the first time you try merging these branches, you will get a lot of conflicts. That is because there is no base branch which these two branches sprung from, so git will have no idea of knowing which version of a file should be the "real" one.