Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active August 9, 2017 21:53
Show Gist options
  • Save magnetikonline/4774656 to your computer and use it in GitHub Desktop.
Save magnetikonline/4774656 to your computer and use it in GitHub Desktop.
Creating a remote Git repository.

Creating a remote Git repository

Before starting, ensure you can ssh user@targetserver successfully - public/private keys are a smart choice here.

Setup of repository at targetserver

Example here assumes all Git repository users are members of a gitusers group, adjust to suit.

$ mkdir -p ~/path/to/repository
$ cd ~/path/to/repository
$ git init --bare --shared=group
$ chgrp -R gitusers ~/path/to/repository

All done on targetserver.

Note: switch --shared=group used with git init adds core.sharedrepository = 1 to ~/path/to/repository/config.

Push first working copy

$ mkdir -p ~/my/new/working/copy
$ cd ~/my/new/working/copy
$ git init
$ touch somefile.txt
$ git add .
$ git commit -m 'Initial commit'
$ git remote add origin user@targetserver:path/to/repository
$ git push -u origin master
$ git fetch
$ git pull

Lock down SSH user to Git only operations

Optional step, but very much recommended. Swapping out the default shell for our Git-only SSH user (e.g. /bin/bash) and replacing with git-shell which only permits Git operations for push/pull/fetch.

$ which git-shell
# take note of full path (e.g. /usr/bin/git-shell)
# then edit /etc/passwd for your Git-only SSH user, or simply...
$ usermod -s /path/to/git-shell [git-username]

Now SSH login attempts to git-username should be rejected, but Git push/pull operations should be allowed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment