轉載自:https://www.cnblogs.com/haimishasha/p/5024772.htmld
1、首先登錄到https://github.com注冊Github帳號,並且創建一個repository。
或者登錄到 https://git.oschina.net/注冊賬號,並且創建一個repository。
例如:注冊的github帳號名為tuanz,創建的repository名稱為bootcat,那么你的倉庫名為bootcat在github上的地址為:
HTTPS : https://github.com/tuanz/bootcat.git
SSH : git@github.com:tuanz/bootcat.git
Subversion: https://github.com/tuanz/bootcat
HTTPS: https://git.oschina.net/repository/powerStationTrainingMIS.git
2、安裝git
3、生成ssh-key的私鑰和公鑰,注意保存。
ssh-keygen -t rsa //一路回車下來
注:Windows下使用git bash操作命令行。
4、 測試是否連接上github服務器
ssh -T git@github.com
(如果是登錄https://git.oschina.net/的話,用 ssh -T git@git.oschina.net)
這時一般會輸出:
.........
Permission denied (publickey).
解決辦法:將上面生成的public key(id_rsa.pub文件)拷貝到github服務器的SSH Keys中,具體操作,
登錄后,點擊右上角的Account settings——> SSH Keys。
ssh -T git@git.oschina.net
5、將項目代碼文件夾上傳到github你的倉庫內
1)在你的代碼目錄下執行以下命令:
在本地建立一個本地庫,用於存放以后要提交的代碼
git bash here
git init
指定遠端倉庫
git remote add origin https://github.com/whu-zhangmin/whuzm.git
或者
https://git.oschina.net/repository/powerStationTrainingMIS.git
git add *
git commit -m "first commit, first version"
git push origin master
(如果沒有配置用戶名和郵箱,那么需要執行以下命令:
git config --global user.name "XXX"
git config --global user.email "XXX@XXX.com" )
如果你的whuzm倉庫中已經含有文件,那么執行這句會提示提交失敗,用戶需要先執行git pull命令
git pull origin master
ok,再次執行git push origin master,成功,到github網上擦看自己的倉庫,發現項目已經提交上去了。
2)如果僅僅是clone倉庫的代碼,可以執行如下命令:
git clone https://github.com/whu-zhangmin/whuzm.git
6、將github上的項目代碼刪除將項目代碼文件夾上
git rm --cached filename
git commit -m "delete"
git push origin branch
--cached 的指令 都是和staging area或者叫index有關的,就是git add了但還沒有commit出去的狀態。
git rm --cached filename 把文件從staging area中刪了,再commit,push,就把github里面那份也刪了。