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

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 合并代码

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值