将已经存在的项目提交到gitlab中

在gitlab中新增用户jack

登录jack这个git用户,然后创建仓库 mxonline

已经写好了部分功能的项目存放在 D:\>cd D:\python\mxonline\
需要推送到gitlab中
运行git_cmd.exe

# 切换到项目目录下
D:\>cd D:\python\mxonline\

# 初始化
D:\python\mxonline>git init
Initialized empty Git repository in D:/python/mxonline/.git/

# 加入主分支
D:\python\mxonline>git remote add origin https://gitlab.example.com/jack/mxonline.git

D:\python\mxonline>git add .
warning: LF will be replaced by CRLF in .idea/misc.xml.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .idea/modules.xml.
The file will have its original line endings in your working directory

# 提交代码失败
D:\python\mxonline>git push -u origin master
To https://gitlab.example.com/jack/mxonline.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://gitlab.example.com/jack/mxonline.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.

# 使用账号密码的方式,照样失败
D:\python\mxonline>git remote set-url origin https://jack:jack2019@gitlab.example.com/jack/mxonline.git

# 最终的解决办法:
通过查看提示信息,我发现,是因为本地仓库和远程仓库的文件不一致所致,也就是说,github允许你本地仓库有的东西,远程仓库里没有,但不允许远程仓库有的东西,你本地仓库没有。问题找到了,解决办法就很简单了,那就是在push之前先同步一下本地仓库与远程仓库的文件。使用以下命令

D:\python\mxonline>git pull --rebase origin master
From https://gitlab.example.com/jack/mxonline
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
First, rewinding head to replay your work on top of it...
Applying: 'init'

D:\python\mxonline>git push -f origin master
Enumerating objects: 1552, done.
Counting objects: 100% (1552/1552), done.
Delta compression using up to 8 threads
Compressing objects: 100% (1491/1491), done.
Writing objects: 100% (1551/1551), 9.44 MiB | 3.46 MiB/s, done.
Total 1551 (delta 350), reused 0 (delta 0)
remote: Resolving deltas: 100% (350/350), done.
To https://gitlab.example.com/jack/mxonline.git
   8c83ef5..5509745  master -> master

至此,本地代码就推送到了远程仓库的master中

# 提示warning: LF will be replaced by CRLF in .idea/misc.xml.

D:\python\mxonline>git add .
warning: LF will be replaced by CRLF in .idea/misc.xml.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .idea/workspace.xml.
The file will have its original line endings in your working directory
# 解决
D:\python\mxonline>git config --global core.autocrlf false

# 修改代码后的提交

D:\python\mxonline>git add .
D:\python\mxonline>git commit -m "update readme"
D:\python\mxonline>git -c http.sslVerify=false push origin master

# 标签

# 查看标签
D:\python\mxonline>git tag
# 命名标签
D:\python\mxonline>git tag mxonline20191016 -m "拉分支前的备份"
# 推送标签
D:\python\mxonline>git push origin mxonline20191016

# 分支的操作

# 查看分支
D:\python\mxonline>git branch
* master

# 创建名为 dns_manage的分支
D:\python\mxonline>git branch dns_manage

D:\python\mxonline>git branch
  dns_manage
* master

# 切换到 dns_manage 分支
D:\python\mxonline>git checkout dns_manage
Switched to branch 'dns_manage'
M       .idea/workspace.xml

# 修改代码,然后提交到分支中,可以看到git的web界面中就有分支了

D:\python\mxonline>git add .

D:\python\mxonline>git commit -m "add dns_manage readme"
[dns_manage a7efacc] add dns_manage readme
 2 files changed, 21 insertions(+), 14 deletions(-)
 create mode 100644 apps/dns_manage/dns_readme.md

D:\python\mxonline>git push origin dns_manage
Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
Delta compression using up to 8 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 782 bytes | 78.00 KiB/s, done.
Total 7 (delta 5), reused 0 (delta 0)
remote:
remote: To create a merge request for dns_manage, visit:
remote:   https://gitlab.example.com/jack/mxonline/merge_requests/new?merge_request%5Bsource_branch%5D=dns_manage
remote:
To https://gitlab.example.com/jack/mxonline.git
 * [new branch]      dns_manage -> dns_manage

# 可以从界面中看到新的分支

将已经存在的项目提交到gitlab的新分支中的更多相关文章

  1. 用idea将本地项目提交到gitlab上

    提交的前提是你必须有gitlab的地址 以下是将本地代码提交到gitlab上 在idea的菜单项选择 VCS>Import into Version Control>Create Git ...

  2. git提交本地代码到新分支

    背景: 从branchA分支拉了一份代码,做了一些修改,但是不想提交到branchA分支,想新建一个分支branchB保存代码. 操作方法: 添加本地需要提交代码 git add . 提交本地代码 g ...

  3. 如何将新建的项目完整的提交到gitlab上?

    描述: 使用idea开发工具新建了一个项目工程,此时此刻工程没有任何的版本控制,代码存放在本地磁盘中,如果需要直接将项目工程代码提交到gitlab上,该如何操作呢? 因为当前没有版本控制,不能像正常的 ...

  4. 从GitLab上创建分支本地拉取项目和提交项目详解

    很多公司前端项目都是部署在GitLab上的,今天我要分享的就是如何从GitLab上创建新的分支并在本地拉取和提交项目 一.在GitLab上面创建自己新的分支 首先你得注册一个账号,登陆之后进入项目Pr ...

  5. 【项目管理】 使用IntelliJ IDEA 将项目发布(提交)到GitLab

    https://blog.csdn.net/zsq520520/article/details/51004721 gitlab地址: http://192.168.1.81:200   idea项目p ...

  6. svn项目迁移至gitlab

    关于svn项目迁移有人可能会说,新建一个git项目,把原来的代码直接扔进去提交不完了吗.恩,是的,没错.但是为了保留之前的历史提交记录,还是得做下面的步骤 首先确保本地正常安装配置好git,具体步骤不 ...

  7. 项目案例之GitLab的数据迁移

    项目案例之GitLab的数据迁移 链接:https://pan.baidu.com/s/1CgaEv12cwfbs5RxcNpxdAg 提取码:fytm 复制这段内容后打开百度网盘手机App,操作更方 ...

  8. 关于如何使用sourcetree将本地项目提交到远端github总结?

    使用sourcetree将本地项目提交到github里,目前来说还是很流行的,我也是听说好玩,所以来琢磨了一下,从环境搭建到配置好,差不多用了一下午加一晚上的时间,有点虐心,好吧,废话不多说,介绍一下 ...

  9. C# 项目提交过程中感受

    C# 项目提交过程中感受 新到一家互联网公司,昨天第一次提交代码,遇到了不少问题,而且大多数是代码格式问题,特此将范的错误记录下来,自我警示. 1. 代码对齐,这个虽然一直也都在注意,不过还是有一行代 ...

随机推荐

  1. Linux防火墙Firewall-cmd 基础

    一.简介 ​ firewall-cmd 是firewalld服务的一个命令行客户端,提供了对防火墙规则的增删查改.firewalld自身并不具备防火墙的功能.它和iptables一样需要通过内核net ...

  2. Python并发编程-并发解决方案概述

    Python并发编程-并发解决方案概述 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.并发和并行区别 1>.并行(parallel) 同时做某些事,可以互不干扰的同一个时 ...

  3. MSSQL-反弹注入

    工具:香港云免费云服务器:http://www.webweb.com 注册使用匿名邮箱:https://bccto.me/ 香港云服务器搭建MSSQL数据库,并建表admin,字段数要大于等于我们想要 ...

  4. python+BeautifulSoup+多进程爬取糗事百科图片

    用到的库: import requests import os from bs4 import BeautifulSoup import time from multiprocessing impor ...

  5. NOIP2019 PJ 对称二叉树

    题目描述 一棵有点权的有根树如果满足以下条件,则被轩轩称为对称二叉树: 二叉树: 将这棵树所有节点的左右子树交换,新树和原树对应位置的结构相同且点权相等. 下图中节点内的数字为权值,节点外的 id 表 ...

  6. QT 子文件的建立(pri)

    QT 在做项目的时候有时会有许多不同种类的文件,如果这些文件放在一起会显得特别乱,我们可以将文件用文件夹分类,这样会比较有条理. 1. 在项目文件夹下建立新的文件夹,并在文件夹中添加文本文档将后缀改为 ...

  7. 02-Flutter移动电商实战-建立项目和编写入口文件

    环境搭建请参考之前写的一篇文章:Flutter_初体验_创建第一个应用 1.创建项目 采用AndroidStudio构建本项目,FIle>New>New Flutter Project… ...

  8. [学习笔记] Miller-Rabin 质数测试

    Miller-Rabin 事先声明,因为菜鸡Hastin知识水平有限就是菜,因此语言可能不是特别规范,仅供理解. step 0 问一个数\(p\)是否为质数,\(p<=10^{18}\). 一个 ...

  9. dbt 0.13.0 新添加特性sources 试用

    dbt 0.13 添加了一个新的功能sources 我呢可以用来做以下事情 从基础模型的源表中进行数据选择 测试对于源数据的假设 计算源数据的freshness source 操作 定义source ...

  10. 用Desmos玩极坐标[适配手机端]

    前言 数学给人的印象一直就是算算算,今天我们不算,我们只玩. 必备条件 ①."呆萌"软件--Desmos 网址:https://www.desmos.com/calculator, ...