GIT提交代码

The error message "fatal: 
not a git repository (or any of the parent directories):
.git" indicates that the current directory is not a Git repository, meaning it doesn't contain a .git directory that Git uses to track your project's history and changes.

错误消息“致命:不是 git 存储库(或任何父目录):.git”表示当前目录不是 Git 存储库,这意味着它不包含.gitGit 用于跟踪项目历史记录和更改的目录。

git init
这将.git在当前文件夹中创建一个新目录,使其成为 Git 存储库。

2.导航到现有的 Git 存储库:如果您打算在现有存储库中运行 Git 命令,请确保导航到正确的目录:cd /path/to/your/git/repository

3.克隆 Git 存储库:如果您需要克隆存储库,可以使用以下git clone命令:

git clone https://github.com/username/repository.git cd repository
$ git push -u origin main
error: src refspec main does not match any
error: failed to push some refs to 'github.com:dopocheng/ry-website.git'

您遇到的错误消息“src refspec main 不匹配任何内容”通常意味着该分支main不存在于您的本地存储库中。如果您尚未创建分支main或您当前位于其他分支,则可能会发生这种情况。

1.检查当前分支:确保您位于要推送的正确分支上。您可以使用以下方法检查当前分支:

git branch

2.main如果分支不存在则创建该分支:如果main分支不存在,您可以创建并切换到该分支:

git checkout -b main

3.添加并提交您的更改:确保在推送之前已添加并提交您的更改:

git add .

git commit -m "Initial commit"

4.推送到远程存储库:现在您可以将main分支推送到远程存储库:

git push -u origin main

$ git push -u origin main
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
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' (ED25519) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

错误“ git@github.com:权限被拒绝(公钥)”表示您的 SSH 密钥配置不正确,或者 GitHub 无法识别您的 SSH 密钥。以下是为 GitHub 配置 SSH 密钥的步骤:

1.检查现有的 SSH 密钥:首先,检查您是否已经有 SSH 密钥:

ls -al ~/.ssh
查找名为id_rsa.pub或 的文件id_ed25519.pub

2.生成新的 SSH 密钥(如有必要):如果您没有现有的 SSH 密钥或想要创建一个新的,请使用以下命令生成它:

ssh-keygen -t ed25519 -C "your_email@example.com"

如果您的系统不支持 Ed25519,请使用:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
按照提示保存密钥并输入密码(可选)。

3.将您的 SSH 密钥添加到 SSH 代理:启动 SSH 代理并添加您的 SSH 密钥:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
如果您生成了 RSA 密钥,请使用id_rsa

4.将 SSH 密钥添加到您的 GitHub 帐户:将 SSH 密钥复制到您的剪贴板:

cat ~/.ssh/id_ed25519.pub

再次,如果您有 RSA 密钥,请使用id_rsa.pub

转到你的 GitHub 帐户设置,导航到“SSH 和 GPG 密钥”,然后单击“新 SSH 密钥”。将密钥粘贴到那里并保存。

5.测试您的 SSH 连接:测试您与 GitHub 的连接:

ssh -T git@github.com
您应该会看到类似“嗨,用户名!您已成功验证,但 GitHub 不提供 shell 访问权限”的消息。

6.推送到您的存储库:现在,尝试再次推送到您的存储库:

git push -u origin main

照这些步骤应该可以解决问题并允许您推送到您的 GitHub 存储库。

 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>

似乎尚未设置远程存储库。要解决此问题,您需要添加远程存储库,然后推送更改。操作方法如下:

1.添加远程存储库:使用以下命令将您的 GitHub 存储库添加为远程存储库:

git remote add origin git@github.com:dopocheng/ry-website.git

2'验证远程存储库:您可以通过运行以下命令来验证远程存储库是否已正确添加:

git remote -v

3.你应该看到类似这样的内容:

origin  git@github.com:dopocheng/ry-website.git (fetch)
origin  git@github.com:dopocheng/ry-website.git (push)

4.推送更改:现在,您可以推送更改

git remote set-url origin <new-url>

5.推送到新远程仓库

git push -u origin main

 git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.

这个错误信息表明当前分支 master 没有配置上游分支(即没有与远程仓库的分支建立追踪关系)。你可以按照提示使用以下命令将本地分支 master 推送到远程仓库,并设置上游分支:

git push --set-upstream origin master
这将同时推送当前分支的内容并建立本地 master 分支与远程 master 分支之间的追踪关系。

1.查看当前分支: 确认你当前所在的分支是 master

git branch
输出应该类似于:* master
2.推送并设置上游分支: 使用以下命令将本地 master 分支推送到远程仓库并建立追踪关系:

git push --set-upstream origin master
3.

  1. 以后推送更改: 一旦建立了上游分支关系,以后你只需要使用 git push 命令即可推送更改。

如果你当前在 main 分支,而不是 master 分支,你可以将命令中的 master 换成 main

git push --set-upstream origin main
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值