配置前提需在本機安裝git,請參考Windows7安裝Git客戶端
一、註冊github帳號
二、建立倉庫html
點擊右上角頭像 - Your repositories - New -建立一個名爲test的倉庫git
點擊Create repository完成建立github
三、配置SSH Keyshell
cd ~/.ssh
ssh-keygen -t rsa -C "github註冊郵箱"
打開github - 右上角頭像 -Setting - SSH and GPG keys - New SSH key
title隨便填寫 Key內容爲.ssh/id_rsa.pub的內容 bash
四、測試是否配置成功ssh
ssh-keygen -t rsa -C "github註冊郵箱"
若是提示Are you sure you want to continue connecting (yes/no)?,輸入yes
而後會看到以下文字表示成功鏈接。
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access. #出現詞句話,說明設置成功。ide
五、配置git
右鍵打開git bash測試
git config --global user.name ‘github用戶名’
git config --global user.email ‘github郵箱’
git config --list # 查看配置信息
六、將本地項目push到GitHubfetch
Administrator@USER-20170516XE MINGW64 ~/Desktop
$ mkdir git
Administrator@USER-20170516XE MINGW64 ~/Desktop/git
$ cd git/
Administrator@USER-20170516XE MINGW64 ~/Desktop/git
$ git init
Initialized empty Git repository in C:/Users/Administrator/Desktop/git/.git/
Administrator@USER-20170516XE MINGW64 ~/Desktop/git (master)
$ echo "hello world" > hello.md
Administrator@USER-20170516XE MINGW64 ~/Desktop/git (master)
$ git add hello.md
Administrator@USER-20170516XE MINGW64 ~/Desktop/git (master)
$ git commit -m "hello.md" # hello.md是個備註 隨便寫
Administrator@USER-20170516XE MINGW64 ~/Desktop/git (master)
$ git status
On branch master
nothing to commit, working tree clean
添加github遠程倉庫
點擊Code - Clone or download - Use SSH
最後得到一個爲 git@github.com:XXX/test.git的一個URL # test倉庫已在第一步建立
spa
Administrator@USER-20170516XE MINGW64 ~/Desktop/git (master)
$ git remote add origin git@github.com:XXX/test.git
Administrator@USER-20170516XE MINGW64 ~/Desktop/git (master)
$ git push -u origin master
Enumerating objects: 1, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 251 bytes | 251.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:qcmoke/test.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
刷新test倉庫,查看是否上傳成功
在使用git 對源代碼進行push到gitHub時可能會出錯,信息以下
能夠經過以下命令進行代碼合併【注:pull=fetch+merge]
git pull --rebase origin master
此時再執行語句 git push -u origin master便可完成代碼上傳到github