推送(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 % 
相关推荐
极小狐10 小时前
CI 流水线提速实战:缓存设计与依赖代理的工程实践
缓存·ci/cd·gitlab·devops
DevOps老兵1 天前
AI Infra实战11:模型部署Pipeline——CI/CD自动化
人工智能·ci/cd·ai·自动化·gitlab
极小狐1 天前
从复制粘贴到可复用组件:极狐GitLab CI/CD 组件目录实战
java·ci/cd·gitlab·devops·组件化
极小狐2 天前
用 Flow 编排 Agent 智能体:极狐GitLab Duo 自定义工作流实战
ai·gitlab·agent·devops·flow·duo
陈皮糖..2 天前
基于 Kubernetes 与 GitLab CI/CD 的云原生自动化交付平台
运维·ci/cd·云原生·架构·kubernetes·自动化·gitlab
11路没有终点2 天前
GitLab CI/CD 高级模式实战:include 模板库 / trigger 子流水线 / matrix 并行
ci/cd·gitlab
11路没有终点3 天前
GitLab CE CI/CD 入门指引手册:从零搭建第一条流水线
ci/cd·gitlab
2501_928996223 天前
Agent 开发的 API 选型:从 Function Calling 到多模型协作的中科热备底层逻辑
服务器·重构·gitlab
何以解忧,唯有..4 天前
Claude Code 常用操作总结
gitlab
GGG7664 天前
K8s1.28 全栈落地|Jenkins+GitLab+Harbor DevOps 流水线封神实战
kubernetes·gitlab·jenkins