Difference between revisions of "Git Guide"
| Line 1: | Line 1: | ||
[[File:git-logo.png]] | [[File:git-logo.png]] | ||
| + | {{fancywarning|Please be aware that this text needs to be revisioned and read to be corrected.}} | ||
| + | |||
| + | __TOC__ | ||
| + | |||
{{fancywarning|Please be aware that this text needs to be revisioned and read to be corrected.}} | {{fancywarning|Please be aware that this text needs to be revisioned and read to be corrected.}} | ||
| Line 5: | Line 9: | ||
== Introduction == | == Introduction == | ||
| + | |||
| + | <tt>Git</tt> is a distributed version control system that let 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 how to will guide you to setup git working with [http://www.github.com Github] using SSH keys. Github is a web based service to store public and private <tt>git</tt> repositories. Funtoo is [https://github.com/funtoo github based]. | ||
== Setup == | == Setup == | ||
=== Recommended packages === | === Recommended packages === | ||
| + | |||
| + | Before we start configuring <tt>git</tt> we recommend to install <tt>[[keychain]]</tt> on our system to manage the SSH keys. So just type <tt>emerge keychain</tt> as root. | ||
=== Backing up existing keys === | === Backing up existing keys === | ||
| + | |||
| + | For security, we will backup or existing keys on <tt>~/.ssh</tt>. It can be possible that our .ssh directory it's empty, so this will just throw us a error. | ||
| + | |||
| + | <pre> | ||
| + | ~ $ cd ~/.ssh | ||
| + | ~/.ssh $ install -d backup-keys | ||
| + | ~/.ssh $ cp . backup-key/ . | ||
| + | </pre> | ||
=== Generating a SSH key === | === Generating a SSH key === | ||
| + | |||
| + | Now we will generate a new key for using it with our <tt>git</tt> account: | ||
| + | |||
| + | <pre> | ||
| + | ~/.ssh $ ssh-keygen -t rsa -C your@account.com | ||
| + | </pre> | ||
| + | |||
| + | Where you replace <tt>your@account.com</tt> for your e-mail account. You can use multiple SSH keys but not with the same e-mail address. If you use multiple accounts, we recommend to just use your <tt>user</tt> and your <tt>hostname</tt>, for example user <tt>funtoo</tt> on <tt>funtoo</tt> machine: <tt>ssh-keygen -t rsa -C funtoo@funtoo</tt>. | ||
| + | |||
| + | This will ask us where to save the file with a default name <tt>id_rsa</tt>. If a file exists it will ask us to overwrite so save it as <tt>github-ssh-key</tt> for example. It will ask us for a password. For that <tt>git</tt> we recommend to stay with a password-less key just for easy interaction. Anyway, you can add a password for it if you feel more comfortable. | ||
| + | |||
| + | You can see a extended explanation of this process at [[Keychain#Generating_a_Key_Pair|generating a key pair]] for <tt>Keychain</tt> wiki entry. | ||
=== Loading the new SSH key === | === Loading the new SSH key === | ||
| + | |||
| + | We have to options to load the new ssh key for <tt>git</tt>: manually or automatically. In any of the two case we will use <tt>keychain</tt> to load it. | ||
==== Manually ==== | ==== Manually ==== | ||
| + | |||
| + | <pre> | ||
| + | ~/.ssh $ keychain --inherit --eval --agents ssh our-ssh-key-name | ||
| + | </pre> | ||
| + | |||
| + | Where <tt>our-ssh-key-name</tt> is the SSH key we generated. | ||
==== Automatically ==== | ==== Automatically ==== | ||
| + | |||
| + | To load the keys manually we need to edit our <tt>.bash_profile</tt> that will start a background process with the indicated ssh keys. So, edit with our editor of choose <tt>~/.bash_profile</tt>: | ||
| + | |||
| + | <pre> | ||
| + | ~/.ssh $ cd .. | ||
| + | ~ $ vim .bash_profile | ||
| + | </pre> | ||
| + | |||
| + | or | ||
| + | |||
| + | <pre> | ||
| + | ~/.ssh $ cd .. | ||
| + | ~ $ nano -w .bash_profile | ||
| + | </pre> | ||
| + | |||
| + | And add at the bottom of the file as a newline: | ||
| + | |||
| + | <pre> | ||
| + | eval `keychain --eval --agents ssh our-ssh-key-name` | ||
| + | </pre> | ||
| + | |||
| + | Where <tt>our-ssh-key-name</tt> is the SSH key we generated. | ||
| + | |||
| + | Exit with <tt>control + 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: | ||
| + | |||
| + | <pre> | ||
| + | ~ $ source .bash_profile | ||
| + | |||
| + | * keychain 2.7.1 ~ http://www.funtoo.org | ||
| + | * Starting ssh-agent... | ||
| + | * Adding 1 ssh key(s): /home/our-user/.ssh/our-ssh-key-name | ||
| + | * ssh-add: Identities added: /home/our-user/.ssh/our-ssh-key-name | ||
| + | |||
| + | ~ $ | ||
| + | </pre> | ||
| + | |||
| + | == Configuring Github == | ||
| + | |||
| + | For using [http://www.github.com Github] we need some basic configuration: | ||
| + | |||
| + | <pre> | ||
| + | ~ $ git config --global user.name "Real Name" | ||
| + | ~ $ git config --global user.email "your@account.com" | ||
| + | </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 with the SSH key generated. | ||
| + | |||
| + | Then you need to add the SSH public key to Github so they can recognize your SSH key. This has to be done throw 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 your <tt>our-ssh-key-name.pub</tt> that you can see 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: | ||
| + | |||
| + | <pre> | ||
| + | ~ $ pre git config --global github.token your-token-here | ||
| + | </pre> | ||
| + | |||
| + | Where <tt>your-token-here</tt> is your **API Token**. | ||
Revision as of 15:24, 29 April 2011
Please be aware that this text needs to be revisioned and read to be corrected.
Contents |
Please be aware that this text needs to be revisioned and read to be corrected.
Introduction
Git is a distributed version control system that let you manage from small to very large projects. You can see a Subversion comparison in the official Git wiki.
This how to will guide you to setup git working with Github using SSH keys. Github is a web based service to store public and private git repositories. Funtoo is github based.
Setup
Recommended packages
Before we start configuring git we recommend to install keychain on our system to manage the SSH keys. So just type emerge keychain as root.
Backing up existing keys
For security, we will backup or existing keys on ~/.ssh. It can be possible that our .ssh directory it's empty, so this will just throw us a error.
~ $ cd ~/.ssh ~/.ssh $ install -d backup-keys ~/.ssh $ cp . backup-key/ .
Generating a SSH key
Now we will generate a new key for using it with our git account:
~/.ssh $ ssh-keygen -t rsa -C your@account.com
Where you replace your@account.com for your e-mail account. You can use multiple SSH keys but not with the same e-mail address. If you use multiple accounts, we recommend to just use your user and your hostname, for example user funtoo on funtoo machine: ssh-keygen -t rsa -C funtoo@funtoo.
This will ask us where to save the file with a default name id_rsa. If a file exists it will ask us to overwrite so save it as github-ssh-key for example. It will ask us for a password. For that git we recommend to stay with a password-less key just for easy interaction. Anyway, you can add a password for it if you feel more comfortable.
You can see a extended explanation of this process at generating a key pair for Keychain wiki entry.
Loading the new SSH key
We have to options to load the new ssh key for git: manually or automatically. In any of the two case we will use keychain to load it.
Manually
~/.ssh $ keychain --inherit --eval --agents ssh our-ssh-key-name
Where our-ssh-key-name is the SSH key we generated.
Automatically
To load the keys manually we need to edit our .bash_profile that will start a background process with the indicated ssh keys. So, edit with our editor of choose ~/.bash_profile:
~/.ssh $ cd .. ~ $ vim .bash_profile
or
~/.ssh $ cd .. ~ $ nano -w .bash_profile
And add at the bottom of the file as a newline:
eval `keychain --eval --agents ssh our-ssh-key-name`
Where our-ssh-key-name is the SSH key we generated.
Exit with control + 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/our-user/.ssh/our-ssh-key-name * ssh-add: Identities added: /home/our-user/.ssh/our-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 with the SSH key generated.
Then you need to add the SSH public key to Github so they can recognize your SSH key. This has to be done throw 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 our-ssh-key-name.pub that you can see 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**.
