使用git bash提交代碼到github託管

一、首先登陸到https://github.com註冊Github賬號,而且建立一個repository。git

   或者登陸到  https://git.oschina.net/註冊帳號,而且建立一個repository。github

例如:註冊的github賬號名爲whu-zhangmin,建立的repository名稱爲whuzm,那麼你的倉庫名爲whuzm在github上的地址爲:bash

HTTPS : https://github.com/whu-zhangmin/whuzm.git服務器

SSH : git@github.com:whu-zhangmin/whuzm.gitssh

Subversion: https://github.com/whu-zhangmin/whuzm測試

 

HTTPS: https://git.oschina.net/repository/powerStationTrainingMIS.gitspa

二、安裝git.net

     

三、生成ssh-key的私鑰和公鑰,注意保存命令行

ssh-keygen -t rsa      //一路回車下來3d

注:Windows下使用git bash操做命令行。

四、 測試是否鏈接上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


五、將項目代碼文件夾上傳到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

 

六、將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裏面那份也刪了。

相關文章
相關標籤/搜索