GIT: how to set a private repository on your server

What you need

  • Server side: SSH access to the server + Git installed
  • Client side:Git shell ((Linux shell access, or Gui Bash for Windows)

Set up remote repository

#login to your server
ssh elvis@phpntips.com
# create repository
mkdir ~/myproject.git
# create empty repository
cd ~/myproject.git
git init --bare

Server: Set SSH keys

# only if you do not have an identity (~/.ssh/id_rsa.pub)
ssh-keygen -t rsa
# copy public key to the server
cat ~/.ssh/id_rsa.pub | ssh elvis@phpntips.com "cat >> ~/.ssh/authorized_keys"

in case youv’e specified a password for the RSA keys, and the password is asked all the time,¬†use ssh-agent

eval `ssh-agent`
ssh-add
# If the keys are set properly, you can now login to the server without specifying any password
ssh elvis@phpntips.com

Local machine: Clone the repository

cd ~/myProject
git clone ssh://user@phpntips.com/~/myproject.git
# make changes and commit
git add
git commit -a && git push

Some GIT tutorials / reference
Official Git tutorial
Git tutorial if you already know SVN
Git reference