使用git bash提交代码到github托管

转载自: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 : [email protected]:tuanz/bootcat.git

Subversion: https://github.com/tuanz/bootcat

 

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

2、安装git

     使用git bash提交代码到github托管

3、生成ssh-key的私钥和公钥,注意保存

ssh-****** -t rsa      //一路回车下来

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

4、 测试是否连接上github服务器

ssh -T [email protected]

(如果是登录https://git.oschina.net/的话,用 ssh -T [email protected])

这时一般会输出:

.........

Permission denied (publickey).

解决办法:将上面生成的public key(id_rsa.pub文件)拷贝到github服务器的SSH Keys中,具体操作,

登录后,点击右上角的Account settings——> SSH Keys。

使用git bash提交代码到github托管

使用git bash提交代码到github托管

使用git bash提交代码到github托管

 

ssh -T [email protected]

使用git bash提交代码到github托管

5、将项目代码文件夹上传到github你的仓库内

1)在你的代码目录下执行以下命令:

在本地建立一个本地库,用于存放以后要提交的代码

git bash here

使用git bash提交代码到github托管

使用git bash提交代码到github托管

git init

使用git bash提交代码到github托管

使用git bash提交代码到github托管

指定远端仓库

git remote add origin https://github.com/whu-zhangmin/whuzm.git

或者

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

使用git bash提交代码到github托管

git add *

使用git bash提交代码到github托管

git commit -m "first commit, first version"

使用git bash提交代码到github托管使用git bash提交代码到github托管使用git bash提交代码到github托管

git push origin master 

使用git bash提交代码到github托管

(如果没有配置用户名和邮箱,那么需要执行以下命令:

git config --global user.name "XXX"

git config --global user.email "[email protected]" )

使用git bash提交代码到github托管

如果你的whuzm仓库中已经含有文件,那么执行这句会提示提交失败,用户需要先执行git pull命令

git pull origin master

使用git bash提交代码到github托管

ok,再次执行git push origin master,成功,到github网上擦看自己的仓库,发现项目已经提交上去了。

使用git bash提交代码到github托管

 

使用git bash提交代码到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里面那份也删了。