5

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

user
  • 17,781
  • 20
  • 98
  • 124

2 Answers2

4

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you. I'll check out the advantages of git bundle & git remote usage. I didn't understand "less chances of file corruption" part. Isn't the non-bundle method more error tolerant because if at a particular instance, the files aren't written to USB properly, only the ones that are being updated in that transaction would be affected. Whereas with the bundle, if the corruption happens, you lose everything. – user Jun 26 '11 at 14:48
  • @buffer: I was only alluding to the number of files being written on the backup drive. With a bundle: only one, with a bare repo: many. – VonC Jun 26 '11 at 16:56
1

You could also use a post-receive hook method by simply setting up a remote for your USB, as well as a remote for your production server. The post-receive hook forces a checkout to where ever you tell it to, so when you need to you could just type "git push usb" and it should checkout -f to your USB stick, or production server.

Check it out... http://toroid.org/ams/git-website-howto

mdpatrick
  • 1,082
  • 9
  • 12