开发者

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 s开发者_开发技巧teps 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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜