1. Preparatory work:
Download install git client http://code.google.com/p/git-osx-installer/downloads/list?can=3 (git client installed, git command on command line )
Sign up for a GitHub account https://github.com/-->pricing and Signup-->create a free accounts
2. Create ssh: ( ssh is created to build trust between Mac and GitHub server )
Open Terminal in Local:
$CD ~/.ssh Check to see if SSH is already present(. SSH is just a demo, it refers to the location of the Mac to store the public key, if the first SSH connection, you can skip this step )
If it exists, first make an existing SSH backup, or build the new SSH into a different directory
If not present, SSH is generated directly from the default parameters
The build process is as follows:
$ssh-keygen-t rsa-c [email protected] ([email protected] refers to the email that was registered on GitHub)
Generating public/private RSA key pair.
Enter file in which to save the key (/users/twer/.ssh/id_rsa): ( Here you can go by default, that is, the public key is stored in/users/twer/.ssh/id_rsa, You can also enter an absolute path to modify the storage location )
Created directory '/users/twer/.ssh '.
Enter passphrase (empty for No passphrase): ( Enter the password for the public key file )
Enter same passphrase again: ( Confirm password for public key file )
Your identification has been saved In/users/twer/.ssh/id_rsa.
Your public key has been saved in/users/twer/.ssh/id_rsa.pub.
The key fingerprint is:
18:16:11:c9:01:6c:48:09:7f:27:c6:43:0d:7f:3f:84 [email protected]
The key ' s Randomart image is:
+--[RSA 2048]----+
|. o.++=== |
|. ooo.+. . |
| .. * = E. |
| o = + O |
| . S O |
| . |
| |
| |
| |
+-----------------+
When done here, it means that you have successfully generated a trusted public key with GitHub on your Mac.
To add SSH to GitHub:
Login to GitHub, select Account settings-->ssh Keys to add SSH
Title:[email protected] (title as far as possible to use their own mailbox, this title and login to the GitHub account of the mailbox is a different concept, can not be the same)
Key: Open the Id_rsa.pub file you generated, copy it to this ( use the CD command to enter the Id_rsa.pub directory, and then use the more id_rsa.pub command to view the contents of the public key)
To test SSH:
$ssh [email protected]
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.
Is you sure want to continue connecting (yes/no)? Yes (this means that the first connection is not successful, yes means a second connection )
warning:permanently added ' github.com,207.97.227.239 ' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
(after the above sentence can be entered into the user name and password, enter the user name and password on GitHub registration, the authentication will be stored locally after a credential, the user name and password will not need to enter again)
Hi xianfuying! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed. ( if Hi xxx appears, it proves that Mac and GitHub have established mutual trust. )
Set local git personal information: ( when submitting data to GitHub, the values set below are displayed to make it easier to find out who did what to the warehouse )
$git config--global user.name "your real name"
$git config--global user.email "[Email protected]"
At this point, the settings for Git and GitHub are complete
3. Submit Code
$git Add *
$git commit-m "Your commit ' s reason" ( commit code to local repository )
$git remote Add alias [email protected]:xxxxx/projectname.git ( define the remote server alias as aliases)
$git pull-u alias Master ( pull code from GitHub to the local repository )
$git Pull-uf alias Master ( forcing code to pull from GitHub to the local repository )
$git push -u alias Master ( push the local repository code to the GitHub repository )
$git remote-v ( view remote server aliases )
$git Remote RM alias (to remove an alias from a server)
How to use Git with GitHub under Mac OS x10.8