1. 前提条件
2. 在GitHub创建一个repository项目
- 进入Github首页,点击New repository新建一个项目
- 填写相应信息后点击create即可
Repository name: 仓库名称
Description(可选): 仓库描述介绍
Public, Private : 仓库权限(公开共享,私有或指定合作者)
Initialize this repository with a README: 添加一个README.md
gitignore: 不需要进行版本管理的仓库类型,对应生成文件.gitignore
license: 证书类型,对应生成文件LICENSE
3. 将Github上的repository项目克隆到本地
- 在本地电脑选择一个用于保存repository的目录
- 在该目录下右击,如果成功安装Git工具将出现Git Gui Here和Git Bash Here,这里我们选择Git Bash Here
- 在创建的repository页面点击Clone or download,复制SSH链接
-
在Git Bash Here执行如下命令
git colone git@github.com:Jeapwu/Notes.git
-
如果出现如下错误
fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. fatal: Could not read from remote repository.Please make sure you have the correct access rights and the repository exists.
解决办法:出现这个问题是因为没有在github账号添加SSH key,可以执行如下命令解决
在Git Bash repository执行
ssh-keygen -t rsa -C "username" (注:username为你Git Bash Here上显示的用户名)
出现出现如下提示,直接按Enter进入下一步
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Jeapw/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
如果执行成功,出现生成的SSH-Key密钥
Your identification has been saved in /c/Users/Jeapw/.ssh/id_rsa
Your public key has been saved in /c/Users/Jeapw/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:cPqCkycrWsZrxmr/87kvKbL8DeOQk2W3NAHywJ+l/i4 Jeapw
The key's randomart image is:
+---[RSA 3072]----+
| .o . |
| .+ .. |
| ..=.. |
| + +. |
| .o.+S |
| . =+o.o |
| .+==o+.o |
| +*o+E+=. |
|+=o=*+**+. |
+----[SHA256]-----+
然后在/c/Users/Jeapw/.ssh/id_rsa.pub中复制生成的密钥
回到Github网站的"account settings",依次点击"Setting" -> "SSH Keys"->"New SSH key",Title处填写“id_rsa.pub”或其他任意信息。 key处原样拷贝复制的生成密钥,至此Github的SSH-Key绑定完成
-
如果出现如下错误
Permission denied (publickey)
解决办法:默认使用id_rsa尝试连接,如果你在新建秘钥的时候使用了自定义的名称,比如github_rsa,你需要在。/ssh目录下再配置一个config文件
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_rsa
- 最后进入打开Git Bash Here的目录便可以执行git clone
4. 将本地项目上传GitHub的repository中
-
执行命令
git add . (注:别忘记后面的.,此操作是把新添加到文件夹下面的文件都添加进来)
-
执行命令
git commit -m "提交信息" (注:“提交信息”里面换成你需要,如“first commit”)
-
如果出现错误
$ git commit -m "2020-5-17-WU" *** Please tell me who you are. Run git config --global user.email "you@example.com" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: unable to auto-detect email address (got 'Jeapw@DESKTOP-KJ8KJ9H.(none)')
错误解决:是因为在创建git文件夹的时候信息不完善导致的,按照提示添加邮箱与用户名即可
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
-
执行命令
git push -u origin master (注:此操作目的是把本地仓库push到github上面,此步骤需要你输入帐号和密码)
-
如果出现如下提示,而事实本地项目并没有上传repository,则是没有执行git commit -m "提交信息"所致
git push -u origin master Everything up-to-date Branch 'master' set up to track remote branch 'master' from 'origin'.
参考博客:
【1】Git的使用--如何将本地项目上传到Github(两种简单、方便的方法)
【2】git "Could not read from remote repository.Please make sure you have the correct access rights."解决方案