Windows 下安装、配置git

本文介绍如何在Windows环境下安装Git,并详细说明了如何设置GitHub账号的用户名和邮箱、生成SSH密钥以及如何将SSH密钥添加到GitHub中,最后还解决了常见的ssh连接错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Windows下安装git,并且与github连接。


1.安装git,下载地址 : https://code.google.com/p/msysgit/ 。

Welcome pageInformationSelect destination locationSelect start menu folderSelect componentsAdjusting your PATH environmentConfiguring the line ending conversions



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
Email

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

  1. Account settings buttonGo to your Account Settings
  2. SSH Keys menuClick "SSH Keys" in the left sidebar
  3. SSH Key buttonClick "Add SSH key"
  4. The key fieldPaste your key into the "Key" field
  5. The Add key buttonClick "Add key"
  6. 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



5.选一个git源测试下,是否可以git clone.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值