A few brief steps to create and populate a remote repository for git.
Assume a local git repo called “~/projects/ldapadmin”.
Now you want to create a “remote” repository on another machine, say “server1”.
Start by making sure your user’s ssh public key is in the corresponding user1 home directory on the remote server under .ssh, and named “authorized_keys” (to avoid having to enter your password on every connection to the server)2.
On the remote server init a “bare” git repository:
cd /data/projects mkdir ldapadmin chown myuser:mygroup ldapadmin chmod g+w ldapadmin cd ldapadmin git init --bare git update-server-info
That last isn’t strictly necessary, but if you’re running a git server using HTTP you’ll want to invoke it.
“mygroup” is a group that users of the remote repo will have in common (e.g. “staff”).
Now go back over to the local machine and change directory into the corresponding repository:
Add the remote repo to your local config as the “origin”:
git remote add origin email@example.com:/data/projects/ldapadmin
Now push your local repo up to the remote repo:
git push -u origin master
(Note: your local repo is “master”, while the remote repo is “origin”)
1You may want to consider creating a special “git” user account to own the repo on the remote machine. The Git Book recommends this approach. For efficiency you could install that git user’s public and private keys under .ssh on your local machine, and then copy the public key under git’s .ssh directory on the remote machine to “authorized_keys” in the same place. You would then log in to the remote server as the git user to push your changes:
git remote add origin firstname.lastname@example.org:/data/projects/ldapadmin git push -u origin master
Personally I’m not a big fan of generic special accounts, but using one in this instance definitely avoids the file ownership and access issues that can arise when multiple users are involved with a repo.
2If you’re on Linux setting this up is easy. Just run “ssh-keygen” and accept the defaults. Then cd into .ssh and copy “id_rsa.pub” to “authorized_keys”. Make sure the .ssh directory is chmod 700 (rwx user only). If on Windows, you may want to try this suggested setup.