1. 程式人生 > >本地git提交到遠端倉庫

本地git提交到遠端倉庫

1、設定全域性變數name、email

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

2、生成公鑰

ssh-keygen -t rsa -C "94*****@qq.com"

3、在github設定頁選擇SSH and GPG keys

選擇New SSH key,填寫title,複製上一步生成的公鑰id_rsa.pub全部內容到Key輸入框中,然後點選Add SSH key,輸入密碼完成認證。

4、複製github工程地址

git clone https://github.com/***.git

5、修改內容之後

git add .
# 隨意寫點註釋吧
git commit -m "***"
git push

之後會彈框輸入使用者名稱密碼,就可以了。

6、不輸入使用者名稱密碼提交遠端倉庫

因為之前複製的地址是https,而不是ssh,開啟.git資料夾中的config檔案

[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
[remote "origin"]
	url = https://github.com/***.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
[gui]
	wmstate = normal
	geometry = 841x483+25+25 189 218

修改url為:[email protected]:***.git,這個連結可以在github網站上覆制

再重新git push

$ git push
The authenticity of host 'github.com (13.229.188.59)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added 'github.com,13.229.188.59' (RSA) to the list of known hosts.
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 40.29 KiB | 138.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:poene/poene.github.io.git
   b531db6..b2bbef5  master -> master