Windows下安装git,并且与github连接。
1.安装git,下载地址 : https://code.google.com/p/msysgit/ 。
2.设置github上的用户名和email地址
Username
First you need to tell git your name, so that it can properly label the commits you make.
git config --global user.name "Your Name Here"# Sets the default name for git to use when you commit
Git saves your email address into the commits you make. We use the email address to associate your commits with your GitHub account.
git config --global user.email "your_email@example.com"# Sets the default email for git to use when you commit
Your email address for Git should be the same one associated with your GitHub account. If it is not, see this guide for help adding additional emails to your GitHub account. If you want to keep your email address hidden, this guide may be useful to you.
3.生成SSH key。
Step 1: Check for SSH keys
First, we need to check for existing ssh keys on your computer. Open up Git Bash and run:
cd ~/.ssh
# Checks to see if there is a directory named ".ssh" in your user directory
If it says "No such file or directory" go to step 2. Otherwise, you already have an existing keypair, and you can skip to step 3.
Step 2: Generate a new SSH key
To generate a new SSH key, enter the code below. We want the default settings so when asked to enter a file in which to save the key, just press enter.
ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
# Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter]
Now you need to enter a passphrase,这里直接两次回车即可。
#Enter passphrase (empty for no passphrase): [Type a passphrase] # Enter same passphrase again: [Type passphrase again]
Which should give you something like this:
#Your identification has been saved in /c/Users/you/.ssh/id_rsa. # Your public key has been saved in /c/Users/you/.ssh/id_rsa.pub. # The key fingerprint is: # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com
Step 3: Add your SSH key to GitHub
Run the following code to copy the key to your clipboard.
clip < ~/.ssh/id_rsa.pub # Copies the contents of the id_rsa.pub file to your clipboard
-
Go to your Account Settings
-
Click "SSH Keys" in the left sidebar
-
Click "Add SSH key"
-
Paste your key into the "Key" field
-
Click "Add key"
- Confirm the action by entering your GitHub password
4.如果遇到
ssh connect to host port 22 bad file number错误,解决方法如下:
在.ssh目录下(默认情况下为 c:/users/用户名/.ssh )添加一个叫做config文件,没有后缀名。
Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443