将本地代码上传到码云以及出现的问题及解决方案

将本地的项目上传到码云

1、码云上创建一个项目 myfirstproject (名字随你)

2、本地创建一个文件夹D:/myfirstproject,然后使用git bash

3、cd 到本地文件夹中D:/myfirstproject,

4、使用 git init 命令 ,初始化一个git 本地仓库(项目),会在本地创建一个 .git 的文件夹

5、使用git remote add origin https://gitee.com/你的码云用户名/testgit //添加远程仓库
具体代码: git remote add origin [email protected]:y1z2h3/myfirstproject_123123123.git

  报错:fatal: remote origin already exists.  (远程仓库已经存在)
  解决办法:
  
1、先删除远程 Git 仓库

 $ git remote rm origin

 2、再添加远程 Git 仓库

 $ git remote add origin [email protected]:y1z2h3/myfirstproject_123123123.git
 如果执行 git remote rm origin 报错的话,我们可以手动修改gitconfig文件的内容
 原文链接:https://blog.csdn.net/top_code/article/details/50381432
  ————————————————

6、使用 git pull origin master 命令,将码云上的仓库pull到本地文件夹

 报错:fatal: Could not read from remote repository.
              Please make sure you have the correct access rights
              and the repository exists.
 原因:你的SSH key没有添加到github帐号设置中
 解决办法:
 1.在终端输入。
 ssh-keygen -t rsa -C "username" (注:username为你git上的用户名)

如果执行成功。返回

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/username/.ssh/id_rsa):

下图说明SSH key就已经生成了。文件目录就是:/c/Users/Administrator/.ssh/id_rsa.pub将本地代码上传到码云以及出现的问题及解决方案_第1张图片
我们执行cat命令查看文件的内容:
这时候会看见:
ssh-rsa AAAAB3NzaC1yc2。。。。。。。。。
后面的内容我省略了
(说明:ssh-rsa 后面的内容这就是你的SSH keys)

把显示出来的SSH keys直接添加到github账户设置里边的SSH keys
————————————————

原文链接:https://blog.csdn.net/u011374880/article/details/79370255

7、将要上传的文件,添加到刚刚创建的文件夹

8、使用git add . 或者 git add + 文件名 (将文件保存到缓存区)

9、使用git commit -m ‘描述新添加的文件内容’ (就是注释) (文件保存到本地仓库)

10、使用git push origin master ,将本地仓库推送到远程仓库
将本地代码上传到码云以及出现的问题及解决方案_第2张图片

你可能感兴趣的:(git入门学习)