Using git with Directory as the Remote Feb 25th 2022 Words: 192

Background

I want to my hexo blog backed up, and sync between several working environments at the same time. Since my blog contains large assetes such as images and attachments, GitHub is not an option and I would like to have the blog synced to my NAS.

At first I am using RSync, but it doesn’t have any version control. After googleing it turns out that GitHub can use a directory as the remote, in my case a directory on my NAS. Therefore, I can have both the version control of the git, and the large file support without setup a git server.

Steps

Create a bare git repo on the NAS

1
git init --bare ~/repos/blog.git

Init a repo in the hexo directory and commit the content:

1
2
3
4
5
6
7
git init

touch .gitignore # exclude node_modules etc.

git add .

git commit -m "Initial commit"

Add the directory of NAS as remote:

1
2
3
git remote add origin /mnt/remote/nas/repos/blog.git

git push origin master

Clone the project to another working environment:

1
git clone /mnt/remote/nas/repos/blog.git

References