将本地文件上传到远程git服务器(转)

前言:我在idea中试了几个小时,项目都传不上去(可能是我不会吧),后来用git命令上传项目发现简单多了~

终于是把项目上传到bitbucket上去了,心塞~~。

1、(先进入项目文件夹)通过命令 gitinit 把这个目录变成git可以管理的仓库

git init

 

2、把文件添加到本地版本库中,使用命令git add 文件;添加到暂存区里面去,如果后面接小数点“.”,意为添加文件夹下的所有文件

git add .

 

3、用命令 git commit告诉Git,把文件提交到仓库。引号内为提交说明

git commit -m 'first commit'

 

4、关联到远程库

git remote add origin 你的远程库地址

如:

git remote add origin git@192.168.31.130:/srv/sample.git

如果上面步骤写错了:则

      git remote rm origin   //删除origin

      git remote add origin git@git.oschina.net:yourname/demo.git   //重新添加origin

5、获取远程库与本地同步合并(如果远程库不为空必须做这一步,否则后面的提交会失败)

git pull --rebase origin master

 

6、将最新的修改推送到远程仓库:gitpush -u origin master

    备注:origin:远程仓库名字;master:分支

注意:我们第一次push的时候,加上-u参数,Git就会把本地的master分支和远程的master分支进行关联起来,我们以后的push操作就不再需要加上-u参数了

如果出现类似下面内容:

Username for 'https://github.com': shiren1118

Password for 'https://shiren1118@github.com':

To https://github.com/shiren1118/iOS_code_agile.git

 ![rejected]        master -> master(non-fast-forward)

error: failed to push some refs to'https://github.com/shiren1118/iOS_code_agile.git'

hint: Updates were rejected because the tip of yourcurrent branch is behind

hint: its remote counterpart. Merge the remote changes(e.g. 'git pull')

hint: before pushing again.

hint: See the 'Note about fast-forwards' in 'git push--help' for details.

 

则输入命令:git push -u origin master –f即可搞定问题

 

 

如果从在git服务器所在主机上的其他账户获取git服务器上面文件,则直接用

gitclone + git仓库的路径,即:gitclone /srv/sample.git/

 



转载自:https://blog.csdn.net/sinat_33366020/article/details/73732769

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值