本地Demo并且链接远程git

使用react官网demo,建立一个小demo

官网Demo:2、搭建本地开发环境
如果需要了解react的demo逻辑,可以参考这篇文章(略显粗糙,笑纳)
不想搭建可以直接从主页 git clone https://github.com/indredK/RDA.git

提交三部曲

语句作用
git add .一键添加所有文件到暂存区
git commit -m “提交备注”把工作区刚添加的东西保存到本地仓库
git push (远程仓库名字) (远程仓库分支)把本地仓库的文件改动推送到远程仓库

① git add .

1、GitHub新建仓库,拷贝仓库地址,本地也新建目录,放两个不相关文件。
2、自建项目用VScode打开,然后进入终端控制面板(ctrl+~)

1、初始化git

PS H:\ApiDemo\my-app> git add .				发现不行,需要初始化git
fatal: not a git repository (or any of the parent directories): .git

解决方法:初始化git

PS H:\ApiDemo\my-app> git init
Initialized empty Git repository in H:/ApiDemo/my-app/.git/

② git commit -m “提交记录”

2、设置提交身份

PS H:\ApiDemo\my-app> git commit -m "官网React的初始代码"  		没有设置提交身份
Author identity unknown

*** 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 '钟@DESKTOP-1FI81QO.(none)')

解决方法:设置提交身份

git config user.email "邮箱@qq.com"
git config user.email
git config user.name '我的名字'
git config user.name  

③ git push origin master = git push (远程仓库名) (分支名)

3、链接远程

PS H:\ApiDemo\my-app> git push					因为没有链接远程
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

    git remote add <name> <url>

and then push using the remote name

    git push <name>
    
PS H:\ApiDemo\my-app>  git push origin CYYY			因为没有链接远程
error: src refspec CYYY does not match any
error: failed to push some refs to 'origin'

所以要设置这个远程仓库名称为origin: 这里有可能因为你的复制出问题,

1、HTTPS链接方式

PS H:\ApiDemo\my-app> git remote add origin https://github.com/indredK/SYYY.git

2、SSH链接方式

PS H:\ApiDemo\my-app> git remote add origin git@github.com:indredK/SYYY.git
`fatal: protocol 'git@https' is not supported`

这里尽量手打,(复制问题)报错说没有这个https,可以通过两种方法(一般就算复制都不会报错了)

git remote set-url origin git@github.com:indredK/SY.git

git remote rm origin 
git remote add origin git@github.com:indredK/SY.git

3、git 方式,未尝试

4、修改分支名,要统一

PS H:\ApiDemo\my-app> git push origin master			本地一般是master,远程默认是main
error: src refspec master does not match any
error: failed to push some refs to 'git@https://github.com/indredK/RDA.git'

1、在github网页上改,请自助

2、改本地分支名

PS H:\ApiDemo\my-app> git branch -m master main
改了分支名字以后重新git add 和 commit  连接远程

5、推送报错

PS C:\Users\apple\Desktop\99> git push origin main  			因为新本地和新仓库没有统一起源
To https://github.com/indredK/SYYY.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/indredK/SYYY.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.

强制推送

PS C:\Users\apple\Desktop\99> git push origin main --force
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 245 bytes | 245.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/indredK/SYYY.git
 + 0ac3a00...0195160 main -> main (forced update)

其他可能会遇到的问题~

随时查看配置 查看配置的一些说明

git config --list

1、SSL验证

PS C:\Users\apple\Desktop\99> git push origin main
fatal: unable to access 'https://github.com/indredK/SYYY.git/': OpenSSL SSL_read: Connection was aborted, errno 10053  

解决方法:可以取消SSL验证(或者有其他方法,自行百度)

PS C:\Users\apple\Desktop\99> git config --global http.sslVerify "false"
PS C:\Users\apple\Desktop\99> git push origin main
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 252 bytes | 252.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/indredK/SYYY.git
   0195160..488af76  main -> main

其他方法

PS H:\React官网实例-只有官网资源\react> git config --global http.proxy 127.0.0.1:1080

2、fatal: protocol ‘git@https’ is not supported

PS H:\ApiDemo\my-app> git push origin main
fatal: protocol 'git@https' is not supported
PS H:\ApiDemo\my-app> git remote add origin git@github.com:indredK/RDA.git

解决方法:链接远程的时候,复制有问题,尽量手打,或者如下解决

Linux系统中ctrl+v操作会给系统中输入特殊字符^?,偏偏这样的字符在git-bash中又看不到,所以克隆错误的链接就出现了这样报错信息。

两种方法,一般就算直接复制都没问题了
1git remote set-url origin git@github.com:indredK/SY.git
2git remote rm origin 
git remote add origin git@github.com:indredK/SY.git

3、error: failed to push some refs to ‘origin或者是url’

PS C:\Users\apple\Desktop\99> git push origin CYYY
error: src refspec CYYY does not match any
error: failed to push some refs to 'origin'

解决方法:需要设置地址和远程仓库名字

PS C:\Users\apple\Desktop\99> git push origin CYYY
error: src refspec CYYY does not match any
error: failed to push some refs to 'https://github.com/indredK/SYYY.git'

解决方法:这是因为远程仓库没有CYYY,傻了吧,主分支是main

4、本地的SSH设置key

问题描述:当新申请的git账号建立仓库,并且使用ssh进行拉取、链接本地与远程,就可能会出现。

PS H:\ApiDemo\my-app> git push origin main
The authenticity of host 'github.com (20.205.243.166)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
git@github.com: Permission denied (publickey).

Please make sure you have the correct access rights
and the repository exists.								(这里是叫你生成key)

PS H:\ApiDemo\my-app> git push origin main
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

PS H:\ApiDemo\my-app> git push origin main
To github.com:indredK/RDA.git
error: failed to push some refs to 'github.com:indredK/RDA.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.

解决方法:设置key

在要上传的文件目录(有.git的文件夹),进行git bash
在这里插入图片描述
如果直接复制进去,Git设置页会弹窗提示,设置key失败

Key is invalid. You must supply a key in OpenSSH public key format

要复制key,必须使用clip < ~/.ssh/id_rsa.pub
在这里插入图片描述
在Git的网站设置好
在这里插入图片描述

5、如果你想在这个编辑器,推送当前版本给其他仓库

1、这是官网推荐

git branch -m main master
git fetch origin
git branch -u origin/master master
git remote set-head origin -a

2、我的做法:换远程链接

git remote add origin https://github.com/indredK/其他仓库名字.git

3、然后强制推送

PS H:\DvaDemo\ant-design-pro> git push origin master -force
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值