Difference between revisions of "Git"

From Redbrick Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
Git is a version control system, like Mercurial with slightly more confusing commands, or like Subversion on steroids. It's a distributed VCS (DVCS), which you can google to find out more about, but if you've only ever used subversion and CVS, you'll find it a little different (hopefully more pleasant) to work with then you're used to.
 
Git is a version control system, like Mercurial with slightly more confusing commands, or like Subversion on steroids. It's a distributed VCS (DVCS), which you can google to find out more about, but if you've only ever used subversion and CVS, you'll find it a little different (hopefully more pleasant) to work with then you're used to.
  
At some stage, someone might put up a full tutorial showing how to use git, but for now, here's how to get and use a repository on redbrick's git hosting area.
+
At some stage, someone might put up a full tutorial showing how to use git, but for now, here's a badly written and terribly phrased guide on how to get and use a repository on redbrick's git hosting area.
  
 
== Getting a git repository on Redbrick ==
 
== Getting a git repository on Redbrick ==
 +
 +
=== Creating an SSH key pair ===
 
Before you can use redbrick's git repositories from one of your computers (or from your redbrick shell), you need to create a public/private SSH keypair there if you haven't already. You'll need to do this for every device/place that you want to access git from. This might sound annoying, but it also lets you use git without having to type a password every time you need to clone/push/pull.
 
Before you can use redbrick's git repositories from one of your computers (or from your redbrick shell), you need to create a public/private SSH keypair there if you haven't already. You'll need to do this for every device/place that you want to access git from. This might sound annoying, but it also lets you use git without having to type a password every time you need to clone/push/pull.
  
Line 10: Line 12:
 
   ssh-keygen -t rsa
 
   ssh-keygen -t rsa
  
 +
You'll probably want to hit enter for most/all of the default options. Especially the first one (where to save the key). When it's done, you'll probably see something like this:
  
 
<pre>
 
<pre>
Line 35: Line 38:
 
[you@your-computer ~]$
 
[you@your-computer ~]$
 
</pre>
 
</pre>
 +
 +
(the little ascii art bit might not show up on older versions of SSH).
 +
 +
This has created two files on your computer - id_rsa and id_rsa.pub. id_rsa is your '''private''' SSH key, and id_rsa.pub is the corresponding public key. You keep id_rsa to yourself, and you can give id_rsa.pub to admins to allow you to access a repository. You can also upload it to a remote server (like redbrick) and put it in a specific location to allow you passwordless logins, but you can google for how to do that.
 +
 +
=== Ask the admins ===
 +
Find an admin, and ask him/her/it if they'll add your repository to the system. They'll need the name of the repo, and any SSH '''public''' keys (not the private ones) belonging to devices that you want to be able to access your repository from sent to them. For example, if you want to be able to access the repository from your laptop, send them the id_rsa.pub file that you generated on your laptop (you'll find it in ~/.ssh). If you want to get at it from your desktop and your redbrick account, send them the id_rsa.pub files from your redbrick account and your desktop.
 +
 +
If you want to add more devices later, you can always ask the admins to add (or remove) some public keys.
 +
 +
=== Create the repository ===
 +
Once the admins have done their work, you need to actually create the repository. You do this on your own computer (or redbrick account, or wherever one of your keys came from). If you asked the admins to create you a repository named "awesomeproject", you'd do the following:
 +
 +
  mkdir awesomeproject
 +
  cd awesomeproject
 +
  git init
 +
  git remote add origin git@git.redbrick.dcu.ie:awesomeproject.git
 +
 
 +
At this point you should do some work, like create a file and put something into it, or whatever. This is where a proper guide to git would be handy. Then commit your changes and do a first push:
 +
 +
  git commit -a -m "My first commit"
 +
  git push origin master:refs/heads/master
 +
 +
''Things to look out for:'' When you're doing the "git remote add origin" command, make sure you add ".git" to the end of the repository name. The system that redbrick uses (called Gitosis, if anybody cares) to manage repositories needs that there. Also, in "git@git.redbrick.dcu.ie", the "git" user isn't a placeholder. You need use that user, not your own redbrick username.

Revision as of 00:23, 19 March 2011

Git is a version control system, like Mercurial with slightly more confusing commands, or like Subversion on steroids. It's a distributed VCS (DVCS), which you can google to find out more about, but if you've only ever used subversion and CVS, you'll find it a little different (hopefully more pleasant) to work with then you're used to.

At some stage, someone might put up a full tutorial showing how to use git, but for now, here's a badly written and terribly phrased guide on how to get and use a repository on redbrick's git hosting area.

Getting a git repository on Redbrick

Creating an SSH key pair

Before you can use redbrick's git repositories from one of your computers (or from your redbrick shell), you need to create a public/private SSH keypair there if you haven't already. You'll need to do this for every device/place that you want to access git from. This might sound annoying, but it also lets you use git without having to type a password every time you need to clone/push/pull.

To do this on a Unixey (Linux/Mac OS X/on redbrick) system, run:

 ssh-keygen -t rsa

You'll probably want to hit enter for most/all of the default options. Especially the first one (where to save the key). When it's done, you'll probably see something like this:

[you@your-computer ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/you/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/you/.ssh/id_rsa.
Your public key has been saved in /Users/you/.ssh/id_rsa.pub.
The key fingerprint is:
58:06:86:0c:83:5e:4e:ab:75:93:96:37:76:42:73:07 you@your-computer.local
The key's randomart image is:
+--[ RSA 2048]----+
| .oo .o  E.      |
|.  +o. + . .     |
|. + . + = .      |
| . + * O .       |
|  o o = S        |
| .               |
|                 |
|                 |
|                 |
+-----------------+
[you@your-computer ~]$

(the little ascii art bit might not show up on older versions of SSH).

This has created two files on your computer - id_rsa and id_rsa.pub. id_rsa is your private SSH key, and id_rsa.pub is the corresponding public key. You keep id_rsa to yourself, and you can give id_rsa.pub to admins to allow you to access a repository. You can also upload it to a remote server (like redbrick) and put it in a specific location to allow you passwordless logins, but you can google for how to do that.

Ask the admins

Find an admin, and ask him/her/it if they'll add your repository to the system. They'll need the name of the repo, and any SSH public keys (not the private ones) belonging to devices that you want to be able to access your repository from sent to them. For example, if you want to be able to access the repository from your laptop, send them the id_rsa.pub file that you generated on your laptop (you'll find it in ~/.ssh). If you want to get at it from your desktop and your redbrick account, send them the id_rsa.pub files from your redbrick account and your desktop.

If you want to add more devices later, you can always ask the admins to add (or remove) some public keys.

Create the repository

Once the admins have done their work, you need to actually create the repository. You do this on your own computer (or redbrick account, or wherever one of your keys came from). If you asked the admins to create you a repository named "awesomeproject", you'd do the following:

 mkdir awesomeproject
 cd awesomeproject
 git init
 git remote add origin git@git.redbrick.dcu.ie:awesomeproject.git
 

At this point you should do some work, like create a file and put something into it, or whatever. This is where a proper guide to git would be handy. Then commit your changes and do a first push:

 git commit -a -m "My first commit"
 git push origin master:refs/heads/master

Things to look out for: When you're doing the "git remote add origin" command, make sure you add ".git" to the end of the repository name. The system that redbrick uses (called Gitosis, if anybody cares) to manage repositories needs that there. Also, in "git@git.redbrick.dcu.ie", the "git" user isn't a placeholder. You need use that user, not your own redbrick username.