1. 程式人生 > >Git連線GitHub

Git連線GitHub

本地初始化一個倉庫,並且關聯到GitHub遠端的新建倉庫。

配置Git使用者和郵箱

配置git全域性使用者和郵箱,連線GitHub的話要配置成GitHub的使用者名稱和郵箱,但是下邊我用的不是GitHub的使用者名稱,也能夠用。

  • git config --global user.name username
  • git config --global user.name email_address
[email protected] MINGW64 /f/mygitpro
$ git config --global user.name RocSun

[email protected]
MINGW64 /f/mygitpro $ git config --global user.email [email protected]

建立SSH密匙對

推送至GitHub時需要用到SSH密匙對,通過git製作金鑰對,Windows下的金鑰儲存在C:\User\UserName\.ssh資料夾下邊,一個公鑰id_rsa.pub檔案,一個私鑰id_rsa檔案。後邊的郵箱是GitHub的郵箱,是否需要密碼看心情。

  • ssh-keygen -t rsa -C '註冊GitHub的郵箱'
[email protected] MINGW64 /f/mygitpro (master)
$ ssh-keygen -t rsa -C '
[email protected]
' Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/Roc/.ssh/id_rsa): Created directory '/c/Users/Roc/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/Roc/.ssh/id_rsa. Your public key has been saved in /c/Users/Roc/.ssh/id_rsa.pub. The key fingerprint is: SHA256:s9KZlaSzp3qlmY/u/nEpxOIpRwV04CNY7WFcpIPxUBE
[email protected]
The key's randomart image is: +---[RSA 2048]----+ | +=E*+ | | o *=+ | | . oo*.o | | ..B . | | S = | | + %. . | | o X=+ o | | +=+ + | | .**oo | +----[SHA256]-----+

ssh建立成功,在GitHub上新增SSH後進行測試。

[email protected] MINGW64 ~
$ ssh -T [email protected]
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)? yes
Warning: Permanently added 'github.com,13.229.188.59' (RSA) to the list of known hosts.
Hi RocsSun! You've successfully authenticated, but GitHub does not provide shell access.

初始化倉庫

將目標資料夾初始化倉庫

  • git init
[email protected] MINGW64 /e/note
$ ls
 Bug/            Flask/        MySQL/     python安裝報錯.md      Vue/
 Django/         Git/          Project/   Redis/                 孫鵬飛.md
 Django回顧.md   JavaScript/   Python/   'Virtualenv&wrapper'/

[email protected] MINGW64 /e/note
$ git init
Initialized empty Git repository in E:/note/.git/

新增到倉庫,並提交到倉庫

將目標檔案新增到倉庫,並提交到倉庫

  • git add file
  • git commit -m 'message'
[email protected] MINGW64 /e/note (master)
$ git add ./*

[email protected] MINGW64 /e/note (master)
$ git commit -m '初始化倉庫,提交以前的所有筆記'
[master (root-commit) 53ab25a] 初始化倉庫,提交以前的所有筆記
 39 files changed, 2260 insertions(+)
 create mode 100644 Bug/Windows-0x80070570.md
 create mode 100644 "Bug/python\345\256\211\350\243\205\346\212\245\351\224\231.md"
 create mode 100644 "Bug/\346\225\260\346\215\256\350\277\201\347\247\273\346\212\245\351\224\231.md"
 create mode 100644 Django/Django-module/Django-Admin.md
 create mode 100644 Django/Django-module/Django-Form&ModelForm.md
 create mode 100644 Django/Django-module/Django-Meta.md
 create mode 100644 Django/Django-module/Django-field.py
 create mode 100644 Django/Django-module/HTTP.md
 create mode 100644 Django/Django-module/MVC.md
 create mode 100644 Django/Django-module/MVT.md
 create mode 100644 Django/Django-rest-framework/Django-rest-framework-Install.md
 create mode 100644 Django/Django-rest-framework/Django-rest-framework-Serializers.md
 create mode 100644 Django/Django-rest-framework/Django-rest-framwork-startquickly.md
 create mode 100644 "Django\345\233\236\351\241\276.md"
 create mode 100644 "Flask/flask\347\232\204\345\256\211\350\243\205\345\217\212\345\277\253\351\200\237\350\277\220\350\241\214.md"
 create mode 100644 "Git/git\347\232\204\345\210\235\346\254\241\344\275\277\347\224\250.md"
 create mode 100644 "Git/git\347\232\204\351\200\211\351\241\271\345\217\202\346\225\260.md"
 create mode 100644 Project/BBS/BBS_database_design.md
 create mode 100644 Project/blog/blog_database.md
 create mode 100644 Python/meriyouxian.py
 create mode 100644 "Redis/Redis\347\232\204\344\273\213\347\273\215.md"
 create mode 100644 Virtualenv&wrapper/Virtualenvwrapper.md
 create mode 100644 "Virtualenv&wrapper/virtualenv\347\232\204\344\275\277\347\224\250.md"
 create mode 100644 Vue/ES6_Class.md
 create mode 100644 "Vue/ES6_Deconstruction(\350\247\243\346\236\204).md"
 create mode 100644 Vue/ES6_DefineVariable.md
 create mode 100644 Vue/ES6_ImportExport.md
 create mode 100644 Vue/ES6_TemplateString.md
 create mode 100644 "Vue/Vue-\347\273\204\345\273\272.md"
 create mode 100644 "Vue/Vue_\346\214\207\344\273\244.md"
 create mode 100644 "Vue/Vue\345\277\203\345\276\227.md"
 create mode 100644 "Vue/Vue\347\232\204\345\237\272\347\241\200\346\223\215\344\275\234.md"
 create mode 100644 Vue/luffy.html
 create mode 100644 Vue/routelink.html
 create mode 100644 Vue/test.html
 create mode 100644 Vue/vue.html
 create mode 100644 "Vue/\347\273\204\345\273\272.html"
 create mode 100644 "python\345\256\211\350\243\205\346\212\245\351\224\231.md"
 create mode 100644 "\345\255\231\351\271\217\351\243\236.md"

關聯遠端倉庫

在GitHub上新建一個空倉庫,並使用git關聯GitHub的新建倉庫。

[email protected] MINGW64 /e/note (master)
$ git remote add origin [email protected]:RocsSun/note.git

推送至GitHub倉庫

第一次推送要使用-u選項。

  • git push -u origin master
[email protected] MINGW64 /e/note (master)
$ git push -u origin master
Enumerating objects: 49, done.
Counting objects: 100% (49/49), done.
Delta compression using up to 4 threads
Compressing objects: 100% (43/43), done.
Writing objects: 100% (49/49), 32.97 KiB | 1.14 MiB/s, done.
Total 49 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), done.
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote:      https://github.com/RocsSun/note/pull/new/master
remote:
To github.com:RocsSun/note.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

[email protected] MINGW64 /e/note (master)