|
/Coding/git:
How to Clone a git Repository
Backup Scenario (Server to Desktop):
The simplest scenario is if you are developing on a server, for instance, and merely want to grab a backup copy on your laptop. Assuming you have already setup and are using a git repository on your server, on your laptop navigate to the directory where you wish to place your backup copy. Then:
git clone ssh://user@server.com/path/to/git/repository/name/
This will create a "name" directory on your laptop, containing all the code and the git repository. If, in future, you wish to copy over changes from server to laptop, cd into directory "name" and initialize "git pull":
cd /path/to/git/repository/name/
git pull ssh://server/path/to/git/repository/name/ HEAD
In the future, to bring the laptop up to date, all that is required is to cd to the "name" directory, and do:
git pull
(ie. git remembers the server and the path on the server.)
Development / Production Scenario (Desktop to Server):
Now suppose you are doing development work on your laptop, and the public, production copy of the code is located on a server[1]. First, ssh into the server and prepare a "bare" repository:
mkdir /path/to/git/repository/name/
cd /path/to/git/repository/name/
git --bare init
Then edit the config file to enable reposharing by adding the line "sharedrepository = 1" under the [core] section. Now back to the laptop.
cd /path/to/git/repository/name/
git remote add origin ssh://yourname@server/path/to/git/repository/name/
git push origin master
The final step should push your latest and greatest software from laptop to server.
[1] http://www.tuxmaniac.com/blog/2009/12/14/setting-up-a-remote-git-server/
posted at: 01:13 | path: /Coding/git | permanent link to this entry