Git使用记录 - 持续更新
本地生成 sshkey
- 打开git命令工具
cd ~/.ssh
ssh-keygen -t rsa -C "实际的eamil地址"
···
// 一路回车,出现以下则说明成功
Your identification has been saved in C:\Users\Administrator/.ssh/id_rsa
Your public key has been saved in C:\Users\Administrator/.ssh/id_rsa.pub
··· - 复制
id_rsa.pub
内的内容,粘贴至远程git
网站设置。
本地切换远程仓库地址
git remote -v
查看本地远程仓库地址git remote rm origin
删除本地仓库地址git remote -v
查看本地仓库地址是否删除git remote add origin xxx
添加新的远程仓库地址,xxx为新的远程仓库地址git remote -v
查看本地更新的仓库地址是否已经生效
将本地项目关联到远程仓库
有两种办法:
一. clone
项目到本地,然后将本地项目内的文件复制过去,add
后推送到远程
二. 合并两个项目
- 本地项目初始化一个git仓库,并将文件加到新建的git仓库中。如果本地项目已经是一个git仓库了,请跳过这一步。
git init
git add .
git commit -m "commit first project" - 添加新的远程仓库地址,可先通过
git remote -v
查看本地是否有仓库地址,没有的话直接添加,有的话通过git remote rm origin
删除。git remote add origin xxx
建议远程地址,使用
SSH
地址,因为使用https
地址时遇到一些鉴权问题。形如git@github.com:xxx/xxx.git
。 - 拉取下远程内容,注意
github
目前主分支名称已由master
修改为main
如果含有共同文件时需要:git pull origin main
git merge origin/main
- 把本地库的所有内容推送到远程库上
git push -u origin main
本地分支名称修改
提交代码时,遇见以下错误
error: src refspec main does not match any. |
查了下,是本地分支名称和远程仓库不匹配,通过以下方式修改
git branch -m "原名称" "想要推送的远程分支名称" |
原名称
可以通过 git branch
查询。
修改SSH链接端口
拉取 github
的代码时,出现错误
> git pull --tags origin main |
原因:拉取方式采用的 SSH
,然后22端口被防火墙屏蔽了,或者被科学上网工具纂改了DNS解析。
解决方案一:使用https协议;
解决方案二:修改端口为443:
- 命令行执行
ssh -T -p 443 git@ssh.github.com
,测试443端口是否可用,示例如下:PS C:\Users\Administrator> ssh -T -p 443 git@ssh.github.com
The authenticity of host '[ssh.github.com]:443 ([20.205.243.160]:443)' can't be established.
ED25519 key fingerprint is SHA256:+***************************
This host key is known by the following other names/addresses:
C:\Users\Administrator/.ssh/known_hosts:1: github.com
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[ssh.github.com]:443' (ED25519) to the list of known hosts.
Hi weizwz! You've successfully authenticated, but GitHub does not provide shell access. - 给
~/.ssh/config
文件里添加如下内容,如果没有config
文件,则新建一个然后重新# Add section below to it
Host github.com
Hostname ssh.github.com
Port 443pull
代码,则恢复正常
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 唯之为之!
评论
ValineGitalk