![](/img/trans.png)
[英]Is there a way to push to a remote Git repository without having to fetch its objects?
[英]Problems in git push without having to clone a repository
假設我在HTML
中完成了一個項目,其中我已經對其進行了一些版本控制。
假設我想在 GitHub 平台上上傳它,我要做的第一件事就是創建一個存儲庫。 然后,將此存儲庫克隆到我的計算機中,將我的項目文件放入該文件夾,最后執行 git push 。
這個過程,我已經執行了,我知道它有效。
但是假設我不想克隆存儲庫並執行前面提到的所有步驟,而是保留我當前項目的文件夾並從那里推送。
為此,我相信我需要使用以下命令:
git remote add origin git@github.com:<mygitnameuser>/<nameofrepository>.git
git push -u origin master
但不幸的是,我最終收到以下錯誤消息:
git@github.com:權限被拒絕(公鑰)。
我檢查了git config --global
中存儲的用戶名和 email ,它們與我的 github 帳戶相同,該怎么辦?
我是否總是需要進行克隆,傳遞文件並在那里執行 git 推送?
我會看看你在 GitHub 上的 ssh 鍵。 它們位於https://github.com/<username>.keys
。 將其與您本地擁有的~/.ssh/id_rsa.pub
(這是針對 Linux 和 Mac。不確定它在 Windows/ git-bash
上的位置)進行比較。
如果它為空/不可用,則通過您的帳戶設置填充它。 在這里查看如何: https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account
您可以按照以下說明檢查 SSH 身份驗證: https://docs.github.com/en/github/authenticating-to-github/testing
檢查您已成功克隆的另一個存儲庫:
cd /path/to/other/repo
git remote -v
如果遠程 URL 以https://
開頭,那么您可以對新存儲庫使用更小的 URL :
git remote set-url origin https://github.com/<mygitnameuser>/<nameofrepository>.git
這樣,您將需要輸入您的 GitHub 用戶名和密碼,而不是處理 SSH 密鑰設置。
對於關鍵錯誤,請關注文檔以獲取更多https://www.atlassian.com/git/tutorials/git-ssh
ssh-keygen -t ed25519 -C "your_email@example.com"
將您的 SSH 密鑰添加到 ssh-agent(僅當您之前沒有創建過,否則跳過此步驟)
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
復制 .pub 文件並將其粘貼到GitHub account settings -> ssh and gpg keys -> add new ssh key -> add a meaningful title like "Home laptop"
然后繼續您的操作,就像您對任何存儲庫所做的那樣。 本文討論了一個類似的問題以及我們不需要克隆存儲庫的工作流程。
完成此操作后,無需克隆存儲庫,只需在 github 中創建一個存儲庫,然后在本地添加遠程源並推送您的更改
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.