20130101 creating a remote git repo - plembo/onemoretech GitHub Wiki

title: Creating a remote git repo link: https://onemoretech.wordpress.com/2013/01/01/creating-a-remote-git-repo/ author: lembobro description: post_id: 3944 created: 2013/01/01 04:25:11 created_gmt: 2013/01/01 08:25:11 comment_status: closed post_name: creating-a-remote-git-repo status: publish post_type: post

Creating a remote git repo

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:

cd ~/projects/ldapadmin

Add the remote repo to your local config as the "origin":

git remote add origin [email protected]:/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 [email protected]:/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.

Copyright 2004-2019 Phil Lembo