简体   繁体   English

git 中的问题无需克隆存储库即可推送

[英]Problems in git push without having to clone a repository

Let's suppose that I have a project done in HTML , in which I have already done some versioning with it.假设我在HTML中完成了一个项目,其中我已经对其进行了一些版本控制。

Assuming that I wanted to upload it on the GitHub platform, the first thing I should do is create a repository .假设我想在 GitHub 平台上上传它,我要做的第一件事就是创建一个存储库 And then, clone this repository into my computer, throw my project files into that folder and finally perform git push .然后,将此存储库克隆到我的计算机中,将我的项目文件放入该文件夹,最后执行 git push

This process, which I have already carried out and I know it works.这个过程,我已经执行了,我知道它有效。

But supposing that I did not want to clone the repository and do all the steps previously mentioned, but rather, keep the folder of my current project and push from there.但是假设我不想克隆存储库并执行前面提到的所有步骤,而是保留我当前项目的文件夹并从那里推送。

For this, I believe that I need to use the following commands:为此,我相信我需要使用以下命令:

git remote add origin git@github.com:<mygitnameuser>/<nameofrepository>.git
git push -u origin master

But unfortunately, I end up getting the following error message:但不幸的是,我最终收到以下错误消息:

git@github.com: Permission denied (publickey). git@github.com:权限被拒绝(公钥)。

I checked the username and email that are stored in git config --global , and they are the same as my github account, what to do?我检查了git config --global中存储的用户名和 email ,它们与我的 github 帐户相同,该怎么办?

Do I always need to make a clone, pass the files and perform git push over there?我是否总是需要进行克隆,传递文件并在那里执行 git 推送?

I would take a look at your ssh keys on GitHub.我会看看你在 GitHub 上的 ssh 键。 They are located at https://github.com/<username>.keys .它们位于https://github.com/<username>.keys Compare that to your ~/.ssh/id_rsa.pub (this is for Linux and Mac. Not sure where it is on Windows/ git-bash ) that you have locally.将其与您本地拥有的~/.ssh/id_rsa.pub (这是针对 Linux 和 Mac。不确定它在 Windows/ git-bash上的位置)进行比较。

If that is empty/unavailable then populate it via your Account settings.如果它为空/不可用,则通过您的帐户设置填充它。 See how here: https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account在这里查看如何: https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account

You can check the SSH authentication by following these instructions: https://docs.github.com/en/github/authenticating-to-github/testing-your-ssh-connection您可以按照以下说明检查 SSH 身份验证: https://docs.github.com/en/github/authenticating-to-github/testing

Check the other repository you already cloned successfully:检查您已成功克隆的另一个存储库:

cd /path/to/other/repo
git remote -v

If the remote URL starts with https:// , then you can use a simalr URL for your new repository:如果远程 URL 以https://开头,那么您可以对新存储库使用更小的 URL :

git remote set-url origin https://github.com/<mygitnameuser>/<nameofrepository>.git

That way, you will need to enter your GitHub username and password instead of dealing with SSH key setup.这样,您将需要输入您的 GitHub 用户名和密码,而不是处理 SSH 密钥设置。

For the key error, follow docs for more https://www.atlassian.com/git/tutorials/git-ssh对于关键错误,请关注文档以获取更多https://www.atlassian.com/git/tutorials/git-ssh

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

Adding your SSH key to the ssh-agent( only if you haven't created previously otherwise just skip this step)将您的 SSH 密钥添加到 ssh-agent(仅当您之前没有创建过,否则跳过此步骤)

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

copy the.pub file and paste it under GitHub account settings -> ssh and gpg keys -> add new ssh key -> add a meaningful title like "Home laptop"复制 .pub 文件并将其粘贴到GitHub account settings -> ssh and gpg keys -> add new ssh key -> add a meaningful title like "Home laptop"

then resume with your operations as you would do for any repository.然后继续您的操作,就像您对任何存储库所做的那样。 This article talks about a similar problem and the workflow where we don't need to clone the repository.本文讨论了一个类似的问题以及我们不需要克隆存储库的工作流程。

Once this is done, instead of cloning the repository just create a repo in github, and in local add the origin of remote and push your changes完成此操作后,无需克隆存储库,只需在 github 中创建一个存储库,然后在本地添加远程源并推送您的更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM