git命令行基本操作和常见错误

匿名 (未验证) 提交于 2019-12-02 23:40:02

git to gitee

使用的gitee(码云) www.gitee.com

Git 全局设置:

git config --global user.name "用户名" git config --global user.email "邮箱"    

1、如果是本地已有的项目要提交到线上指定的空仓库

  • 先进入项目目录下,执行
$ git init 
  • 如果要查看项目目录的情况,执行
$ git status 
  • 将项目缓存到本地仓库
$ git add . 
  • 将项目提交到本地仓库
$ git commit -m "提示信息" 
  • 将项目缓存到远程仓库
$ git remote add origin https://gitee.com/用户名/仓库名.git 
  • 将项目提交
$ git push -u origin master 

创建 git 仓库:

mkdir my-test   // 创建一个本地项目目录 cd my-test    // 进入项目目录 git init    // 初始化git仓库 touch README.md   // 创建readme文件,使用脚手架项目的话自带 git add README.md  // 添加指定的文件到本地仓库 git commit -m "first commit"   // 提交,并添加提示信息 git remote add origin https://gitee.com/用户名/仓库名.git  //提交到远程仓库 git push -u origin master  // 添加到主分支 

已有仓库

cd my-test  // 进入本地项目目录 git remote add origin https://gitee.com/用户名/仓库名.git   // 提交到远程仓库 git push -u origin master    // 添加到主分支 

git常见错误

1、

fatal: remote origin already exists. 

(致命错误信息: 远程仓库信息已经存在.)

这个问题出现在提交git仓库的时候

$ git remote add origin https://gitee.com/用户名/仓库名.git  

解决方案:

1. 删除Git仓库中的origin信息

$ git remote rm origin 

2. 重新添加Git仓库中的origin信息

$ git remote add origin https://gitee.com/用户名/仓库名.git 

3. 此时问题就解决啦,直接使用提交命令就可以提交到GitHub上了

$ git push -u origin master 

或者可以打开.git文件夹下边的config文件
将文件呢内的

[remote "origin"] 	url = https://gitee.com/用户名/仓库名.git 	fetch = +refs/heads/*:refs/remotes/origin/* 

删除掉即可

2、

error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 

出现这个错误,在git bash中写以下命令即可

$ git config http.sslVerify "false" 

3、

ssh variant 'simple' does not support setting port 

解决办法: 在git bash中输入命令

 git config --global ssh.variant ssh 

4、

 ! [rejected]        master -> master (fetch first)  error: failed to push some refs to 'https://gitee.com/用户名/仓库名.git'  hint: Updates were rejected because the remote contains work that you do  hint: not have locally. This is usually caused by another repository pushing  hint: to the same ref. You may want to first integrate the remote changes  hint: (e.g., 'git pull ...') before pushing again.  hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

原因:github中的README.md文件不在本地代码目录中

方法:git pull --rebase origin master 合并代码

文章来源: https://blog.csdn.net/qq_44492790/article/details/91420253
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!