推送(push)项目到gitlab

文章目录

  • [1、git init](#1、git init)
    • 1.1、在当前目录中显示隐藏文件:
    • 1.2、查看已有的远程仓库
    • [1.3、确保你的本地机器已经生成了 SSH 密钥:](#1.3、确保你的本地机器已经生成了 SSH 密钥:)
    • [1.4、将生成的公钥文件(通常位于 ~/.ssh/id_rsa.pub)复制到 GitLab 的 SSH 设置中:](#1.4、将生成的公钥文件(通常位于 ~/.ssh/id_rsa.pub)复制到 GitLab 的 SSH 设置中:)
    • [1.5、测试 SSH 连接是否成功:](#1.5、测试 SSH 连接是否成功:)
  • [2、git remote add origin git@192.168.31.20:xiaoding/xubaoxian.git](#2、git remote add origin git@192.168.31.20:xiaoding/xubaoxian.git)
    • [2.1、修改现有远程仓库的 URL](#2.1、修改现有远程仓库的 URL)
  • 3、验证远程仓库连接
  • [4、git add .](#4、git add .)
  • [5、git push -u origin master](#5、git push -u origin master)
bash 复制代码
cd existing_folder
git init
git remote add origin git@192.168.31.20:xiaoding/xubaoxian.git
git add .
git commit -m "Initial commit"
git push -u origin master

1、git init

bash 复制代码
dgq@dgqdeMac-mini xubaoxian % git init
Reinitialized existing Git repository in /Users/dgq/WeChatProjects/xubaoxian/.git/

1.1、在当前目录中显示隐藏文件:

bash 复制代码
dgq@dgqdeMac-mini xubaoxian % ls -a
.				.eslintrc.js			app.js				components			pages				sitemap.json
..				.git				app.json			config				project.config.json		utils
.DS_Store			api				app.wxss			icons				project.private.config.json	wxs

1.2、查看已有的远程仓库

bash 复制代码
dgq@dgqdeMac-mini xubaoxian % git remote -v
origin	https://gitee.com/i-know-the-little-demon/xubao-fresh.git (fetch)
origin	https://gitee.com/i-know-the-little-demon/xubao-fresh.git (push)

现在我们登录的是gitee,那么现在要登录gitlab,登录步骤在这个博客 登录GitLab方式

1.3、确保你的本地机器已经生成了 SSH 密钥:

bash 复制代码
dgq@dgqdeMac-mini xubaoxian % ssh-keygen -t rsa -b 4096 -C "1325182344@qq.com"

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/dgq/.ssh/id_rsa): 
Created directory '/Users/dgq/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/dgq/.ssh/id_rsa
Your public key has been saved in /Users/dgq/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:WU3rTEkx2PGTymuho/gsyQXtExIQllg3j5wmezuAGfk 1325182344@qq.com
The key's randomart image is:
+---[RSA 4096]----+
|   o=+o    o*o   |
|  .o.o.=  .+.= . |
|  o . =o. . = +  |
|   = +o oo = . . |
|  o E .+S.  *    |
|     o .+  . o   |
|     .oo .o o    |
|      ++ . o     |
|      .o+        |
+----[SHA256]-----+

1.4、将生成的公钥文件(通常位于 ~/.ssh/id_rsa.pub)复制到 GitLab 的 SSH 设置中:

bash 复制代码
dgq@dgqdeMac-mini xubaoxian % cat ~/.ssh/id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCraVvft5764GU2hn17Ee7GTozIdk7B8yXZZnIrZgShRip/t0KmQFnjkgv5qfRE49YOABXmCyPEZqKSqsXEoi12eSbFtYb7Rtz3YLVk7UqzMsS+6kYqLSUCJCPjkSYtrCpP7dV0ZiQ51CnWf80h0lYBk20RkyHYYC8w90ORt0IXbXeFm/r6jHSk7RUAgNazqgoz/Lhm9pSuRFWp5CcXsltF7EmZWke0/6aMMOHnKgJDfufxNebGjaxPS4oNBYkkskJukE2cO4hkp2gu7jSoWPZjsssboaYprVGqlJoJGvD2z5p7AWZ9kFt6XTCvJ4HB9xHlRfBJTvbQgnVPacMTrd+kAolSlBFKeRTmMxS+tbVAhiLLBDoEH8JcejmngbucBgVsRXkV16bKrC904RC3QiyGSyMvXoKzBlmcwP5QaSgeqNJvuwPj1beIGwc37UvwBL/mK5v3e8aGFhWCLFYb/DNS/aa3but3eFE4lGhlqeaF1mEezyPc8LDe4WZHiKQE4GuLHqSNmOKL54IvLONTP399prbuxRXe9eX9j/UpE5LANdDLwfUOV1cXTESm4QuAB4PvkKGAYdi27zRZy08AeAPo90cIfYFq5wCuzGnpcdwKdTcbpFNZEm1sRphpAKoLZq+q/juNmDh+4iLPkzqmQ+YxNIq1X1hXuMH8ydw4VtKWaQ== 1325182344@qq.com
  • 打开 GitLab > 右上角头像 > Settings > SSH Keys > 粘贴公钥。

1.5、测试 SSH 连接是否成功:

bash 复制代码
dgq@dgqdeMac-mini xubaoxian % ssh -T git@192.168.31.20

The authenticity of host '192.168.31.20 (192.168.31.20)' can't be established.
ED25519 key fingerprint is SHA256:TKY7z/gGPwvcD7f/QZi71iQ4baK9rMnY8Gh54Lxqy1I.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.31.20' (ED25519) to the list of known hosts.
Welcome to GitLab, @xiaoding!

2、git remote add origin git@192.168.31.20:xiaoding/xubaoxian.git

bash 复制代码
dgq@dgqdeMac-mini xubaoxian % git remote add origin git@192.168.31.20:xiaoding/xubaoxian.git
error: remote origin already exists.
dgq@dgqdeMac-mini xubaoxian % git remote -v
origin	https://gitee.com/i-know-the-little-demon/xubao-fresh.git (fetch)
origin	https://gitee.com/i-know-the-little-demon/xubao-fresh.git (push)

2.1、修改现有远程仓库的 URL

如果你希望继续使用 origin 名称,但更改其指向新的远程仓库:

bash 复制代码
dgq@dgqdeMac-mini xubaoxian % git remote set-url origin git@192.168.31.20:xiaoding/xubaoxian.git

dgq@dgqdeMac-mini xubaoxian % git remote -v
origin	git@192.168.31.20:xiaoding/xubaoxian.git (fetch)
origin	git@192.168.31.20:xiaoding/xubaoxian.git (push)

3、验证远程仓库连接

运行以下命令测试是否能够成功连接到远程仓库:

bash 复制代码
dgq@dgqdeMac-mini xubaoxian % git fetch origin
  • 如果没有报错,则说明远程仓库连接正常。
  • 如果有报错,请检查是否有网络、SSH Key 配置问题,或仓库权限不足。

4、git add .

bash 复制代码
dgq@dgqdeMac-mini xubaoxian % git add . 
dgq@dgqdeMac-mini xubaoxian % git commit -m "Initial commit"
[master d6b0d83] Initial commit
 Committer: dgq <dgq@dgqdeMac-mini.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1745 files changed, 13115 insertions(+), 35971 deletions(-)
 create mode 100644 .DS_Store
 create mode 100644 api/auth.js
 create mode 100644 api/brand.js
 create mode 100644 api/category.js
 create mode 100644 api/dashboard.js

5、git push -u origin master

bash 复制代码
dgq@dgqdeMac-mini xubaoxian % git push -u origin master
Enumerating objects: 1022, done.
Counting objects: 100% (1022/1022), done.
Delta compression using up to 10 threads
Compressing objects: 100% (994/994), done.
Writing objects: 100% (1022/1022), 1.43 MiB | 30.40 MiB/s, done.
Total 1022 (delta 283), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (283/283), done.
To 192.168.31.20:xiaoding/xubaoxian.git
 * [new branch]      master -> master
branch 'master' set up to track 'origin/master'.
dgq@dgqdeMac-mini xubaoxian % 
相关推荐
wan_da_ren11 小时前
Windows 环境下使用 Go Modules 拉取带外层 Basic Auth 的私有 GitLab 仓库 — 完整解决方案
windows·golang·gitlab
llc的足迹11 小时前
docker 中 gitlab 和 gitlab runner 离线安装及配置
docker·容器·gitlab
一念一花一世界1 天前
CI/CD工具选型:GitLab CI与Arbess全面对比指南
ci/cd·gitlab·jenkins·cicd·arbess
张童瑶1 天前
Gitlab 搭建本地私有仓库
gitlab
HIT_Weston1 天前
51、【Ubuntu】【Gitlab】拉出内网 Web 服务:http.server 单/多线程分析(三)
ubuntu·http·gitlab
LSL666_1 天前
16 gitlab
gitlab
自己的九又四分之三站台1 天前
GitLab vs Gitea 全面对比:企业级 DevOps 还是轻量级私有仓库?
ci/cd·gitlab·devops·gitea
地球没有花1 天前
gitlab cicd 部署阿里云k8s
阿里云·ci/cd·kubernetes·gitlab
java_logo1 天前
GITLAB Docker 容器化部署指南
linux·运维·数据库·docker·容器·eureka·gitlab
成为你的宁宁1 天前
【Jenkins+GitLab 自动化构建部署实战教程:环境介绍、服务部署、密钥配置、项目推送与自动编译打包全流程详解】
自动化·gitlab·jenkins