2015-09-05  git 

Setup a Git Remote Repository

Create an SSH key-pair

[local: ~] $ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/USERNAME/.ssh/id_rsa): /home/USERNAME/.ssh/id_rsa.MYSERVER
Enter passphrase (empty for no passphrase): XXXXXXXX
Enter same passphrase again: XXXXXXXX
Your identification has been saved in /home/USERNAME/id_rsa.MYSERVER. # your private key
Your public key has been saved in /home/USERNAME/id_rsa.MYSERVER.pub. # your public key
The key fingerprint is:
XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX USERNAME@localhost
The key's randomart image is:
+--[ RSA 2048]----+
|        ..       |
|       . .       |
|        +  .     |
|         +  +    |
|       .So +.    |
|  .+.+.o++.+     |
|   * +..  ...    |
|  o = .          |
|E. .             |
+-----------------+
[local: ~] $ cd ~/.ssh
[local: ~/.ssh] $ ls
id_rsa.MYSERVER
id_rsa.MYSERVER.pub
[local: ~/.ssh] $ cat id_rsa.MYSERVER.pub
ssh-rsa AAAAB3NzaC1yc...(snip)...QqFPlfdgf2ogxwgZ USERNAME@localhost
[local: ~/.ssh] $ (Now, send id_rsa.MYSERVER.pub to your remote machine.)

Setup

[remote: ~] $ (OK, I have id_rsa.MYSERVER.pub now.)
[remote: ~] $ cat id_rsa.MYSERVER.pub
ssh-rsa AAAAB3NzaC1yc...(snip)...QqFPlfdgf2ogxwgZ USERNAME@localhost
[remote: ~] $ cat id_rsa.MYSERVER.pub >> ~/.ssh/authorized_keys

Initialize

[remote: ~] $ whoami
USERNAME
[remote: ~] $ hostname
SERVER.EXAMPLE.COM
[remote: ~] $ mkdir test.git
[remote: ~/test.git] $ cd test.git
[remote: ~/test.git] $ git init --bare
[remote: ~/test.git] $ pwd
/home/USERNAME/test.git
[remote: ~/test.git] $ exit

Push

[local: ~] $ mkdir test
[local: ~] $ cd test
[local: ~/test] $ git init
[local: ~/test] $ echo "Hello, World." > readme
[local: ~/test] $ git add .
[local: ~/test] $ git commit -m "Initial commit."
[local: ~/test] $ git remote add origin ssh://USERNAME@SERVER.EXAMPLE.COM/home/USERNAME/test.git
[local: ~/test] $ git push origin master
[local: ~/test] $ cd ..

Clone

[local: ~/] $ mkdir clonetest
[local: ~/] $ cd clonetest
[local: ~/clonetest] $ git clone ssh://USERNAME@SERVER.EXAMPLE.COM/home/USERNAME/test.git
[local: ~/clonetest] $ cd test
[local: ~/clonetest/test] $ cat readme
[local: ~/clonetest/test] $ vi readme
[local: ~/clonetest/test] $ git add .
[local: ~/clonetest/test] $ git commit -m "Add ..."
[local: ~/clonetest/test] $ git push origin master
[local: ~/clonetest/test] $ cd

SSH Config

[local: ~] $ cat ~/.ssh/config
Host MYSERVER
    HostName SERVER.EXAMPLE.COM
    User USERNAME
    Port 22
    IdentityFile ~/.ssh/id_rsa.MYSERVER
[local: ~] $ mkdir configtest
[local: ~] $ cd configtest
[local: ~/configtest] $ cd configtest
[local: ~/configtest] $ git clone ssh://MYSERVER/home/USERNAME/test.git
[local: ~/configtest] $ cd test
[local: ~/configtest/test] $ cat readme

See Also

 2015-09-05  git