+++ title = "Cool things I didn't knew: multiple Git repositories in a single directory" author = ["MichaƂ Sapka"] date = 2024-10-29T22:51:00+01:00 categories = ["blog"] draft = false weight = 2001 image_dir = "blog/images" image_max_width = 600 Abstract = "How to combine files from multiple repositories in one directory?" Listening = "John Coltrane - A Love Supreme" +++ I am trying to find a nice way to add sync to my org. I can't use any syncthing nor dropbox on my work computer, but I won't ever put google drive on my personal one. When asked on Mastodon, people proposed me to use git. I'm sure you know that `git worktree` allows you to have multiple branches available at the same time. But, did you knew that the `.git` folder, although standard, is not mandated? In fact, all your git data can live anywhere. First, you need a standard `.git` folder, so let's ```shell git init mv .git .git-one ``` Now, if you `git status`, there won't be no git repository found. But we can force git to use our new dir ```shell git --git-dir=.git-one status ``` This tricks allows us to have any number of git repositories co-exist in the same directory. Those can share files (just `git add` them), or be completely different. So, want to have a `work_org` and `private_org` side by side? No problem! Each repository has it own: - origin - staging area - history and so on. Pretty cool, I might add.