Wojtek Wencel
Wojtek Wencel

Reputation: 2117

How to automatically back up a local Git repo to the same machine?

I know there are posts already asking about it, but they mostly refer to doing manual backups, not automatic.

I'm going to use Git for Unity game development so I have to use LFS. I'm working solo so I want to keep everything local.

I want to set it up like this: working directory on my SSD and LFS cache on my bigger HDD. I also want to back up my repo to the HDD (without the LFS cache, it's already there), but I'm not sure what's the proper way of doing that. I though about setting up a remote on my HDD and then pushing to it from my repo on SSD. This seems like the best way to keep a backup of my repo on the other drive to me, but I'm not sure if it's possible. I didn't find many articles detailing how to set this up so I'm concerned that I'm missing some better solution. Is this even possible, if no what's the "proper" way of doing it?

Upvotes: 1

Views: 1269

Answers (2)

Geno Chen
Geno Chen

Reputation: 5214

I though about setting up a remote on my HDD and then pushing to it from my repo on SSD.

This seems you are going to set up a Git server, which can be used as a "remote backup" of your repository.

Also, you may know that a remote repo can be at your computer local.

And, you may consider some other backup method like rsync besides using a Git remote repository.

Upvotes: 1

Mark Adelsberger
Mark Adelsberger

Reputation: 45719

A remote can be local or remote; this makes no difference to git. You just have to specify an appropriate URL for the remote (or for any reference to a repo).

I often use file://localhost/path/to/repo

On a windows machine, that might look like file://localhost/c/repos/myRepo or something of the sort.

If that doesn't clarify how you would set it up, then you may need to be more specific about what question you have; this should work just the same as setting up any other remote.

LFS needn't be an issue here; since you're just wanting to back up the core repo's database, the remote doesn't even need an LFS configuration.

As for automation, I suppose you could use hooks. For example, a post-commit hook could push all refs to the remote, so that all new commits get replicated automatically. (A hook is just a script placed in the .git/hooks directory, which git will execute when certain events occur.) You can look up the git documentation on hooks for information about what all of the possible events are.

Upvotes: 2

Related Questions