本地git仓库和远端关联,创建一个新的项目提交到远端

  • 创建远端项目

          这个不用说了,在github或者本地的gitlab上创建,拿到ssh或者Https地址

  • 创建本地仓库

          1.新建文件夹,在文件夹内打开终端

          2.初始化本地的文件夹为一个git可以管理的仓库

              

git init
Initialized empty Git repository in X:/javaCode/workspace_MyBatis/.git/

 

  • 把本地仓库和远端仓库关联
$ git remote add origin https://git.oschina.net/wang522shuo/mybatistest.git

 

  • 把文件放入本地仓库
$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        ws.mybatis/

nothing added to commit but untracked files present (use "git add" to track)
$ git add .

  

$ git commit -m"提交"
[master (root-commit) dd7804b] 提交
 9 files changed, 369 insertions(+)

 

  • 把本地库推送到远端仓库

 

$ git push -u origin master
To https://git.oschina.net/wang522shuo/mybatistest.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://git.oschina.net/wang522shuo/mybatistest.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 

这个时候会报错

这里出错的原因是由于我在Coding创建项目的时候,勾选了启用Readme文件初始化项目,导致远程库有一个Readme文件即非空的仓库,本地必须先把远程的文件pull下来(git pull origin master)然后才能push (git push origin master).

终端输入 git pull origin master 之后,会进入vim的编辑状态

这个界面是在pull服务器代码和你本地代码做合并的时候,让你填写合并信息的。你可以不用管。如果公司有固定的提交格式的时候你就需要: 按键盘上字母i,进入insert模式去修改最上边一行合并信息。然后在输入  :wq  保存退出即可。

 如果合并信息没有强制要求格式,有以下几种办法:

1.输入:wq   直接保存退出    (一般这个)

2.输入  :q 就是直接退出

3.在键盘上按control + z   (强制退出)

再次输入git push origin master  (git pull --rebase origin master)  就可以了 ,然后就可以在coding上看到同步了

转载于:https://www.cnblogs.com/langtutengyixiao/p/7087356.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值