Difference between revisions of "Git Guide"

From Funtoo Linux
Jump to: navigation, search
m
m
Line 89: Line 89:
 
~ $
 
~ $
 
</pre>
 
</pre>
 
=== Checking if all worked ===
 
 
Now you can check if all worked. Just run:
 
 
<pre>
 
~ $ ssh git@github.com
 
The authenticity of host 'github.com (207.97.227.239)' can't be established.
 
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
 
Are you sure you want to continue connecting (yes/no)? yes
 
Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.
 
Permission denied (publickey).
 
</pre>
 
 
It will refuse your public key but now you have added the host to known hosts.
 
  
 
== Configuring Github ==
 
== Configuring Github ==
Line 135: Line 120:
  
 
If you have now added you first github repository you can start working with it.
 
If you have now added you first github repository you can start working with it.
 +
 +
=== Checking if all worked ===
 +
 +
Now you can check if all worked. Just run:
 +
 +
<pre>
 +
~ $ ssh git@github.com
 +
The authenticity of host 'github.com (207.97.227.239)' can't be established.
 +
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
 +
Are you sure you want to continue connecting (yes/no)? yes
 +
Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.
 +
Permission denied (publickey).
 +
</pre>
 +
 +
It will refuse your public key but now you have added the host to known hosts.
  
 
== Needed commands for git ==
 
== Needed commands for git ==

Revision as of 10:19, 13 May 2011

Git-logo.png

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 git based and stored at github.

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-keys/.

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.

Select Account Settings
Click on Add another public key
Save the key

Finally navigate to Account Settings > Account Admin and look for your API Token.

Copy the API Token

Copy it and add it to your github config with:

~ $ git config --global github.token your-token-here

Where your-token-here is your API Token.

If you have now added you first github repository you can start working with it.

Checking if all worked

Now you can check if all worked. Just run:

~ $ ssh git@github.com
The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.
Permission denied (publickey).

It will refuse your public key but now you have added the host to known hosts.

Needed commands for git

clone, pull, commit, push

example git config

Personal tools
Namespaces

Variants
Actions
Categories
Toolbox
Stuff