一、Git上传github

生成本地密钥

ssh-keygen -t rsa -C “youxiang@qq.com

之后添加进github的SSH设置里。

验证是否正常连接。

ssh -T git@github.com

二、拉取到本地

git config –global user.name “注册名”

git config –global user.email “zhuceyouxiang@qq.com

git init

git remote add origin github项目的.ssh连接

git pull –rebase origin main

三、上传代码

配置

git config –global user.name “注册名”

git config –global user.email “zhuceyouxiang@qq.com

上传git

git init

git add .

git commit -m “说明”

建立连接

git remote add origin github项目的.ssh连接

提交

git push -u origin main

https://www.yiibai.com/git/git_push.html

以签名形式提交代码(安全、可信,防冒充)

打开git,检查是否有GPG命令行,Windows版本的Git发行包中,已经包含了可用的GPG命令行。

gpg –version

生成自己的GPG密钥,之后输入个人信息与保护密码。

gpg –full-generate-key

列出您拥有其公钥和私钥的长形式 GPG 密钥。 签名提交或标记需要私钥。

gpg –list-secret-keys –keyid-format=long

使用gpg --gen-key亦可生成密钥,但是会略去自定义密钥参数的步骤,对于一般场合的使用问题不大。

关联Github

上一步中记下的密钥ID来导出对应GPG密钥的公钥字符串,从 -----BEGIN PGP PUBLIC KEY BLOCK----- 开始,到 -----END PGP PUBLIC KEY BLOCK----- 结束(包含两部分)。

gpg –armor –export key_id

GPG密钥绑定Git

1
git config --global user.signingkey 3AA5C34371567BD2

电子邮件与 GPG 密钥关联

gpg –edit-key GPG key ID

带签名提交,之后输入GPG密钥的保护密码。

1
git config commit.gpgsign true
1
git commit -S -m "your commit message"

设置 Git 全局提交都要签名

git config –global commit.gpgsign true

https://blog.csdn.net/shenhai_/article/details/100132896

https://docs.github.com/cn/authentication/managing-commit-signature-verification/checking-for-existing-gpg-keys

https://docs.github.com/cn/authentication/managing-commit-signature-verification/generating-a-new-gpg-key

https://zhuanlan.zhihu.com/p/76861431#:~:text=%E7%94%9F%E6%88%90%E8%87%AA%E5%B7%B1%E7%9A%84GPG%E5%AF%86%E9%92%A5%20%E6%89%93%E5%BC%80Git%20Bash%EF%BC%8C%E8%BF%90%E8%A1%8C%20gpg,--full-generate-key%20%EF%BC%8C%E6%A0%B9%E6%8D%AE%E6%8F%90%E7%A4%BA%EF%BC%8C%E8%BE%93%E5%85%A5%E7%9B%B8%E5%BA%94%E7%9A%84%E4%B8%AA%E4%BA%BA%E4%BF%A1%E6%81%AF%EF%BC%88%20%E9%9C%80%E8%A6%81%E6%B3%A8%E6%84%8F%E7%9A%84%E6%98%AF%E9%82%AE%E7%AE%B1%E5%BF%85%E9%A1%BB%E8%A6%81%E4%BD%BF%E7%94%A8%E5%9C%A8Github%E4%B8%AD%E9%AA%8C%E8%AF%81%E8%BF%87%E7%9A%84%E9%82%AE%E7%AE%B1%20%EF%BC%89%E3%80%81%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AF%86%E9%92%A5%E5%8F%82%E6%95%B0%E3%80%81%E8%AE%BE%E7%BD%AE%E7%A7%81%E9%92%A5%E5%AF%86%E7%A0%81%E7%AD%89%E7%AD%89%EF%BC%8C%E5%8D%B3%E5%8F%AF%E7%94%9F%E6%88%90%E8%87%AA%E5%B7%B1%E7%9A%84GPG%E5%AF%86%E9%92%A5%E3%80%82

显示错误

可能原因是github邮箱与本地仓库邮箱未同步。

$进入本地仓库目录,邮箱为github上的邮箱 git config --local user.name "Firstname Lastname" git config --local user.email "your_email@example.com"

https://blog.csdn.net/qqqqll3/article/details/90410155

克隆别人的仓库

git init

git clone github项目的.ssh连接

git命令

git remote -v

用于显示当前本地仓库连接的远程仓库,可以连接好几个。

git remote -remove origin

删除远程连接。

git pull

用于从远程获取代码并合并本地的版本。

https://www.runoob.com/git/git-pull.html

git默认的master分支与Github默认的main分支的冲突报错

git默认的master分支,而Github最新默认的main分支,github的仓库中没有master这个分支,我们本地的仓库没有main分支,将本地仓库的master分支改名为main分支。

git branch -m master main

https://blog.csdn.net/gongdamrgao/article/details/115032436

git pull与git clone区别

https://www.php.cn/tool/git/487356.html

git pull适用于从用户有权限的仓库下拉代码,不管本地有没有代码。

git pull origin master与git pull –rebase origin master的区别

区别主要是在远程与本地代码的合并上面。

https://www.cnblogs.com/ellen-mylife/p/12794245.html

Git教程

https://www.yiibai.com/git/git_push.html