一、首先登陆到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
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里面那份也删了。