推送(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 % 
相关推荐
极小狐9 小时前
GitLab 18.2 发布几十项与 DevSecOps 有关的功能,可升级体验【二】
ci/cd·gitlab·devsecops·devops·极狐gitlab
不念霉运3 天前
2025 Gitee vs. GitLab:全面对比与选择指南
gitee·gitlab
水瓶_bxt3 天前
创建 GitLab Runner 使用CICD自动化部署容器
eureka·自动化·gitlab
黑心的奥利奥4 天前
Docker配置Gitlab-runner实现自动化容器化部署前端项目
docker·自动化·gitlab
wuzuyu3655 天前
在腾讯云上安装gitlab
云计算·gitlab·腾讯云
xiaodaiwang5 天前
OpenEuler 22.03 系统上安装配置gitlab runner
gitlab
TimberWill5 天前
gitlab私服搭建
gitlab
中东大鹅5 天前
访问 gitlab 跳转 0.0.0.0
gitlab
guygg886 天前
配置本地git到gitlab并推送
git·gitlab
大A崛起6 天前
Gitlab-CI实现组件自动推送
ci/cd·gitlab·github