推送(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 [email protected]:xiaoding/xubaoxian.git](#2、git remote add origin [email protected]: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 [email protected]: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 "[email protected]"

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 [email protected]
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== [email protected]
  • 打开 GitLab > 右上角头像 > Settings > SSH Keys > 粘贴公钥。

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

bash 复制代码
dgq@dgqdeMac-mini xubaoxian % ssh -T [email protected]

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 [email protected]:xiaoding/xubaoxian.git

bash 复制代码
dgq@dgqdeMac-mini xubaoxian % git remote add origin [email protected]: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 [email protected]:xiaoding/xubaoxian.git

dgq@dgqdeMac-mini xubaoxian % git remote -v
origin	[email protected]:xiaoding/xubaoxian.git (fetch)
origin	[email protected]: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 <[email protected]>
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 % 
相关推荐
星释1 天前
如何自动部署GitLab项目
gitlab
keson要进步1 天前
CICD实战(二)-----gitlab的安装与配置
linux·运维·gitlab
猫头虎1 天前
[特殊字符]解决 “IDEA 登录失败。不支持早于 14.0 的 GitLab 版本” 问题的几种方法
java·ide·网络协议·http·https·gitlab·intellij-idea
风早君1 天前
jenkins集成gitlab发布到远程服务器
服务器·gitlab·jenkins
大白要努力!3 天前
在 Android Studio 中使用 GitLab 添加图片到 README.md
android·gitlab·android studio
星释3 天前
如何编写GitLab-CI配置文件
ci/cd·gitlab
馨羽的玩具4 天前
gitlab rss订阅失败
gitlab
t198751284 天前
jenkins结合gitlab实现CI
ci/cd·gitlab·jenkins
一颗小豆4 天前
07-接着玩-linux的CD/CI全流程体验
gitlab