Difference between revisions of "Git Guide"
(updated typos) |
|||
| Line 6: | Line 6: | ||
== Introduction == | == Introduction == | ||
| − | <tt>Git</tt> is a distributed version control system that | + | <tt>Git</tt> is a distributed version control system that lets you manage from small to very large projects. You can see a <tt>Subversion</tt> comparison in the official [https://git.wiki.kernel.org/index.php/GitSvnComparison <tt>Git</tt> wiki]. |
| − | This | + | This howto will guide you through the setup process of git [http://www.github.com Github] and the usage of SSH keys to work with <tt>git</tt>. Github is a web based service to store public and private <tt>git</tt> repositories. Funtoo's portage tree and overlays are [https://github.com/funtoo github based]. |
== Setup == | == Setup == | ||
| Line 14: | Line 14: | ||
=== Recommended packages === | === Recommended packages === | ||
| − | Before | + | Before you start configuring <tt>git</tt> we recommend that you have installed <tt>[[keychain]]</tt> on your system to manage the SSH keys. So just type <tt>emerge -avt keychain</tt> as root. |
=== Backing up existing keys === | === Backing up existing keys === | ||
| − | For security | + | For security reasons you will backup your existing keys in <tt>~/.ssh</tt>. It can be possible that your .ssh directory is empty, so this will just result in an error message. |
<pre> | <pre> | ||
| Line 28: | Line 28: | ||
=== Generating a SSH key === | === Generating a SSH key === | ||
| − | Now | + | Now you need to generate a new key for using with your Github account: |
<pre> | <pre> | ||
| Line 34: | Line 34: | ||
</pre> | </pre> | ||
| − | Where you replace <tt>your@account.com</tt> | + | Where you replace <tt>your@account.com</tt> with your e-mail account that you like to use on Github. You can use multiple SSH keys but not with the same e-mail address. If you use multiple accounts, we recommend to use your <tt>user</tt> and your <tt>hostname</tt>, for example user: <tt>funtoo</tt> on host: <tt>funtoo</tt>: <tt>ssh-keygen -t rsa -C funtoo@funtoo</tt>. |
| − | This will ask | + | This will ask you where to save the file with a default name <tt>id_rsa</tt>. If a file exists it will not ask us to overwrite it, so save it for example as <tt>github-ssh-key</tt> or <tt>user@hostname</tt>, where you replace user with your username and hostname with your hostname. It will ask you for a password. For that <tt>git</tt>-key we stay with a password-less key, so you can easily interact with github. Anyway if you feel more comfortable with a password add it here. |
| − | You can see a extended explanation of this process | + | You can see a extended explanation of this process in [[Keychain#Generating_a_Key_Pair|generating a key pair]] at <tt>Keychain</tt> wiki entry. |
=== Loading the new SSH key === | === Loading the new SSH key === | ||
| − | + | You have now two options to load the new ssh key for <tt>git</tt>: manually or automatically. In both cases we will use <tt>keychain</tt> to do it. | |
==== Manually ==== | ==== Manually ==== | ||
<pre> | <pre> | ||
| − | ~/.ssh $ keychain --inherit --eval --agents ssh | + | ~/.ssh $ keychain --inherit --eval --agents ssh your-ssh-key-name |
</pre> | </pre> | ||
| − | Where <tt> | + | Where <tt>your-ssh-key-name</tt> is the SSH key you generated above. |
==== Automatically ==== | ==== Automatically ==== | ||
| − | To load the keys | + | To load the keys automatically we need to edit your <tt>.bash_profile</tt> that will start a background process with the indicated ssh keys. So edit that file with your editor of choose: |
<pre> | <pre> | ||
| Line 68: | Line 68: | ||
</pre> | </pre> | ||
| − | And add at the bottom of the file | + | And add at the bottom of the file a new line with the following content: |
<pre> | <pre> | ||
| − | eval `keychain --eval --agents ssh | + | eval `keychain --eval --agents ssh your-ssh-key-name` |
</pre> | </pre> | ||
| − | Where <tt> | + | Where <tt>your-ssh-key-name</tt> is the SSH key you generated above. <tt>your-ssh-key-name</tt> could also be a list of keys like <tt>key1 key2 ... keyn</tt>, what would mean that keychain loads all this keys to one ssh-agent and not starting several subprocesses for it. |
| − | Exit with <tt> | + | Exit with <tt>CTRL + X</tt> and save with yes for <tt>nano</tt> or <tt>Esc</tt> and <tt>:wq!</tt> for <tt>vim</tt>. |
Now you need to reload the profile to load the key: | Now you need to reload the profile to load the key: | ||
| Line 85: | Line 85: | ||
* keychain 2.7.1 ~ http://www.funtoo.org | * keychain 2.7.1 ~ http://www.funtoo.org | ||
* Starting ssh-agent... | * Starting ssh-agent... | ||
| − | * Adding 1 ssh key(s): /home/ | + | * Adding 1 ssh key(s): /home/username/.ssh/your-ssh-key-name |
| − | * ssh-add: Identities added: /home/ | + | * ssh-add: Identities added: /home/username/.ssh/your-ssh-key-name |
~ $ | ~ $ | ||
| Line 100: | Line 100: | ||
</pre> | </pre> | ||
| − | Where <tt>Real Name</tt> will be the name displayed on commits and <tt>your@account.com</tt> the e-mail account (or user@hostname) you used | + | Where <tt>Real Name</tt> will be the name displayed on commits and <tt>your@account.com</tt> the e-mail account (or user@hostname) you used to generate a SSH key for. |
| − | + | Next you need to add the SSH public key to Github so they can recognize your SSH key. This has to be done by their website. Login with your user or create a new one and navigate to: <tt>Account Setting > Click SSH Public Key > Click Add another public key</tt>. Add a title and the output of <tt>your-ssh-key-name.pub</tt> that you can be seen with <tt>cat ~/.ssh/our-ssh-key-name.pub</tt> and save it. | |
Finally navigate to <tt>Account Settings > Account Admin</tt> and look for your **API Token**. Copy it and add it to your github config with: | Finally navigate to <tt>Account Settings > Account Admin</tt> and look for your **API Token**. Copy it and add it to your github config with: | ||
Revision as of 15:52, 29 April 2011
Please be aware that this text needs to be revisioned and read to be corrected.
Contents |
Introduction
Git is a distributed version control system that lets you manage from small to very large projects. You can see a Subversion comparison in the official Git wiki.
This howto will guide you through the setup process of git Github and the usage of SSH keys to work with git. Github is a web based service to store public and private git repositories. Funtoo's portage tree and overlays are github based.
Setup
Recommended packages
Before you start configuring git we recommend that you have installed keychain on your system to manage the SSH keys. So just type emerge -avt keychain as root.
Backing up existing keys
For security reasons you will backup your existing keys in ~/.ssh. It can be possible that your .ssh directory is empty, so this will just result in an error message.
~ $ cd ~/.ssh ~/.ssh $ install -d backup-keys ~/.ssh $ cp . backup-key/ .
Generating a SSH key
Now you need to generate a new key for using with your Github account:
~/.ssh $ ssh-keygen -t rsa -C your@account.com
Where you replace your@account.com with your e-mail account that you like to use on Github. You can use multiple SSH keys but not with the same e-mail address. If you use multiple accounts, we recommend to use your user and your hostname, for example user: funtoo on host: funtoo: ssh-keygen -t rsa -C funtoo@funtoo.
This will ask you where to save the file with a default name id_rsa. If a file exists it will not ask us to overwrite it, so save it for example as github-ssh-key or user@hostname, where you replace user with your username and hostname with your hostname. It will ask you for a password. For that git-key we stay with a password-less key, so you can easily interact with github. Anyway if you feel more comfortable with a password add it here.
You can see a extended explanation of this process in generating a key pair at Keychain wiki entry.
Loading the new SSH key
You have now two options to load the new ssh key for git: manually or automatically. In both cases we will use keychain to do it.
Manually
~/.ssh $ keychain --inherit --eval --agents ssh your-ssh-key-name
Where your-ssh-key-name is the SSH key you generated above.
Automatically
To load the keys automatically we need to edit your .bash_profile that will start a background process with the indicated ssh keys. So edit that file with your editor of choose:
~/.ssh $ cd .. ~ $ vim .bash_profile
or
~/.ssh $ cd .. ~ $ nano -w .bash_profile
And add at the bottom of the file a new line with the following content:
eval `keychain --eval --agents ssh your-ssh-key-name`
Where your-ssh-key-name is the SSH key you generated above. your-ssh-key-name could also be a list of keys like key1 key2 ... keyn, what would mean that keychain loads all this keys to one ssh-agent and not starting several subprocesses for it.
Exit with CTRL + X and save with yes for nano or Esc and :wq! for vim.
Now you need to reload the profile to load the key:
~ $ source .bash_profile * keychain 2.7.1 ~ http://www.funtoo.org * Starting ssh-agent... * Adding 1 ssh key(s): /home/username/.ssh/your-ssh-key-name * ssh-add: Identities added: /home/username/.ssh/your-ssh-key-name ~ $
Configuring Github
For using Github we need some basic configuration:
~ $ git config --global user.name "Real Name" ~ $ git config --global user.email "your@account.com"
Where Real Name will be the name displayed on commits and your@account.com the e-mail account (or user@hostname) you used to generate a SSH key for.
Next you need to add the SSH public key to Github so they can recognize your SSH key. This has to be done by their website. Login with your user or create a new one and navigate to: Account Setting > Click SSH Public Key > Click Add another public key. Add a title and the output of your-ssh-key-name.pub that you can be seen with cat ~/.ssh/our-ssh-key-name.pub and save it.
Finally navigate to Account Settings > Account Admin and look for your **API Token**. Copy it and add it to your github config with:
~ $ pre git config --global github.token your-token-here
Where your-token-here is your **API Token**.
