Setting up & using Git on Ubuntu

Installing Git and doing the initial set up is pretty straight-forward. I’m using Ubuntu 13.10 – open Terminal and run the following command:

sudo apt-get install git-core

You’ll need to create a Git configuration file in your home directory – I’ll use vi, because it’s just so user friendly:

sudo vi ~/.gitconfig

You should now be starting from a fresh/empty file, close vi and run the following commands to add details to your configuration file:

git config --global user.name "gitUserName"
git config --global user.email user.email@domain.co.uk

If you use GitHub use the same details you use to access the web site. Git is now installed and your user details should be saved in the configuration file.

Get the latest updates

Adding the latest version of Git from their package repository – useful on Ubuntu LTS versions where the Ubuntu Universe version is older than the Git version:

sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get upgrade

Accessing GitHub

If you’re using GitHub as your central repository then you’ll need to do a few things to allow yourself access. First off you’ll need to install OpenSSH and create an authentication key. Once you’ve done that you will need to copy the contents of your public key and add it to your account on GitHub. Click on the account settings link on GitHub – it’s in the top right corner: github-account-links On the left hand side there is a link labelled ‘SSH keys’ – click that: ssh-link-in-left-panel-on-github The resulting page lists any keys you currently have associated to your account. In the top right of the content of the page you’ll have a link to ‘Add SSH key’: add-ssh-link-on-github The next page is quite straight-forward, give your key a title so you can identify it later and then paste the contents of your public key file into the other field: add-ssh-key-form-on-github Save your changes.

Using Git

Some common commands for everyday usage of Git from the command line. Change directory so you are in your repository – then run these commands depending on what you want to do.

Clone a repository

git clone git://github.com/path/to.git

Get status

git status

Update local

git pull

Commit changes

git add "path/to/file.ext"
git commit -m "A useful commit message"
git push

Or if you have a few changes to add at the same time you can run:

git add -A
git commit -m "A useful commit message"
git push

1 thought on “Setting up & using Git on Ubuntu”

Leave a Reply