Saturday 16 June 2012

Install git on ubuntu

This is a brief step by step guide to install git and hook up to github using ssh.

Get git
$sudo apt-get install git-core

Check the install
$which git
$git --version

Configure git
$git config --global user.name "Firstname Lastname"
$git config --global user.email you@domain.com

Set up your ssh key
$ssh-keygen -t rsa -C "you@domain.com"
[hit enter]
set your key password
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
The key fingerprint is:
fingerprint you@domain.com

Add the key to github
$less ~/.ssh/id_rsa.pub
Copy the key to your clipboard

Go to your github Account Settings

Click "SSH Keys" in the left sidebar
Click "Add SSH key"
Paste your key into the "Key" field
Click "Add key"
Confirm the action by entering your GitHub password

Verify the key
$ssh -T git@github.com
Y
enter the key password

You should get a success, "but GitHub does not provide shell access".

Set up a test repo
$mkdir repo-name
$cd repo-name
$git init
$touch README
$git add README
$git commit -m 'first commit'
$git remote add origin https://github.com/gitusername/repo-name.git
$git push -u origin master

you'll get a 403 error

Getting past the 403 error
$vi .git/config
change https for ssh
$git push -u origin master

you'll get a Permission denied (publickey) error

hmmm

$ssh-add -l shows the same fingerprint as the account settings on github
$ssh -vT git@github.com comes back saying I have successfully authenticated...

Getting past the Permission denied error
$cd ~/.ssh
$vi config

Host github.com
User git
Port 22
Hostname github.com
IdentityFile ~/.ssh/id_rsa
TCPKeepAlive yes
IdentitiesOnly yes

$git push -u origin master

Happy days! You should now see the README file on github

1 comment: