Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git setup for backup & sync between 2 computers

I'm new to git. Need some advise to know if my setup is correct. Please read below :

I'm using git for 2 separate projects on my development computer and want to backup everything on a USB drive (setup as a git bare repo). Additionally, I want to sync these projects on another computer (for deployment).

The 2 projects paths on computer1 are

/machine1/path/proj1
/machine1/path/proj2 

This is how I've setup (repeated exact same steps for proj2)

#Initialize git repo
cd /machine1/path/proj1
git init
git add .
git commit -a -m "proj 1 first commit"

#Backup on USB
cd /usb/backup
mkdir proj1.git
cd proj1.git
git init --bare
cd /machine1/path/proj1
git push --mirror /usb/backup/proj1.git

#Clone to other computer
cd /machine2/path
git clone /usb/backup/proj1.git

#After making changes on machine1, I update machine2 using this command
git pull /usb/backup/proj1.git

Question:

  1. Are these steps correct for (i) setup, (ii) backup on USB, (iii) sync to other machines? Or is there a right/better way to do it ?
  2. I mistakenly executed these commands

cd /machine2/path/proj2
git pull /usb/backup/proj1.git  

I expected git to show an error message ... something like "trying to sync proj2 with proj1 repo" but instead it created a subdirectory of proj2 inside proj1. Is there a shortcoming in my setup ? I expected an action like this would require a --force switch or else produce a fatal error

like image 718
user Avatar asked Jun 26 '11 08:06

user


People also ask

Can you use git as a backup?

Local Backups with Git Clone in Cron ScriptsTo create a local backup, you will write a script to clone your repositories on a regular basis using cron jobs. Instead of writing over one clone, you'll capture multiple snapshots of the repository taken at different times.

Can you backup a GitHub repository?

You can use the API or a third-party tool to back up your repository. To download an archive of your repository, you can use the API for user or organization migrations.

Do we need to backup GitHub?

Backups help prevent lost work, but they also ensure your data is always accessible. Having a complete copy of your repository (saved externally) protects you from relying on external services, i.e. GitHub. After all, no service can guarantee 100% uptime.

How do I backup a branch?

To do this you need three steps: Make an empty backup repository on the external backup disk; Point your current git repository at the backup repository with git remote add ; Send the changes to the backup repository with git push .


1 Answers

The steps are essentially correct, except I prefer using git bundle with an USB key (i.e. I prefer having on an USB key one file per project, instead of many files: less chances of file corruption). You can create one with tags and branches, and then pull from those bundles.

Regarding the pull issue, I would recommend setting a remote:

got remote add origin /usb/backup/proj1.git

That way, you would "pull origin" instead of manually entering an address (that you can mix up).

See Groking git remote usage for more.

like image 129
VonC Avatar answered Sep 23 '22 16:09

VonC