As mentioned in other answers, you could move the directories under a common parent directory and track it as one repository or use the sub-modules approach.
In case you don't want to move the existing directories, you could treat the root directory /
as your parent directory (provided you have the necessary permissions).
# Initialize git repo at root
git init /
# Add the directories to be tracked
git add /path/to/directory1 /path/to/directory2
However, this causes a lot of files to be untracked (see git status
output) since the repository is initialized at the root directory. One way to ignore all these files is to add them to $GIT_DIR/info/exclude
file.
Open an editor to modify this file /.git/info/exclude
to :
# ignores everything under root directory
/*
# except these paths
!/path/to/directory1/*
!/path/to/directory2/*
You can confirm with git status
that only the directories you added previously have been staged for the new commit and it should no longer show any untracked files.
If satisfied, create your first commit
git commit -m "Your commit message"