分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

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

发布时间:2023-09-06 01:56责任编辑:郭大石关键词:文件上传

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

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

原文地址:https://www.cnblogs.com/simple1368/p/9084077.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved