Sunshine Tech and Media

Sync Files Between a Computer and VPS w/ Git

git
git

Git is a version control system that allows you to track changes to files and collaborate with other developers. It can also be used to sync files between a VPS (Virtual Private Server) and a computer. Here’s how to do it in a few short steps:

  1. Install git on both the VPS and your computer if it’s not already installed. On the VPS, run sudo apt-get install git.
  2. Create a git repository on your VPS by navigating to the desired directory and running git init.
  3. Add your files to the repository using git add ..
  4. Commit the changes with git commit -m "Commit message".
  5. On your computer, create a new repository with git init and add the VPS repository as a remote with git remote add origin ssh://user@your_server_ip:port/path/to/repo. Replace the placeholders with your VPS login information.

To automatically sync your files, you can use cronie, a task scheduler that allows you to run commands at specific intervals. Here’s how to set it up:

  1. On the VPS, install cronie with sudo apt-get install cronie.
  2. To edit your crontab file, run crontab -e.
  3. Add a line to the file to run the git push command at the desired interval. For example, to push changes every hour, you can use the following line: 0 * * * * git push origin master.
  4. Save the file and exit.

On your computer, you can also use cronie to automatically pull changes from the VPS. Here’s how:

  1. Install cronie with sudo apt-get install cronie.
  2. To edit your crontab file, run crontab -e.
  3. Add a line to the file to run the git pull command at the desired interval. For example, to pull changes every hour, you can use the following line: 0 * * * * git pull.
  4. Save the file and exit.

That’s it! You can now use git and cronie to automatically sync files between your VPS and computer.

If you are in need of VPS or domain registration services, we would recommend NameHero.

If you are interested in web design, managed hosting, or marketing services, we offer them at Sunshine Tech and Media.