Git ssh

From wikinotes
Revision as of 05:07, 5 February 2022 by Will (talk | contribs) (→‎Clone Repo)

You can host your git repos on your own servers using SSH.

Setup

Create Repo

On the remote server that you wish to store repo, create it.

cd /path/projectname
git init --bare

On your computer, create an empty repo, and push to remote server

git remote add origin ssh://git@gitbox:8610/home/git/my_project
git --set-upstream origin --all
git push

Clone Repo

From this point onwards, you can clone the repo like this:

git clone ssh://user@10.10.10.10:/path/to/repo

You can also shorten it with an ssh config

# ~/.ssh/config
Host myhost
  Hostname 10.10.10.10
  IdentityFile ~/.ssh/mykey
  User user
git clone ssh://myhost:/path/to/repo

# you can also change the SSH command used
GIT_SSH_COMMAND="ssh -i ~/.ssh/foo" git clone ssh://myhost:/path/to/repo

# you can also specify it in the git config, but you'll need to configure it for each clone

Configuration

Read-Only Access

You can setup read-only access, by creating users and changing user/file permissions