gitlab相关操作

2025.06.11今天我学习了如何在终端使用git相关操作:

一、需要修改新的仓库git地址的时候:

(1)检查当前远程仓库

git remote -v

输出示例:

origin https://github.com/old-repo.git (fetch)

origin https://github.com/old-repo.git (push)

方案一:删除已有的远程仓库并重新添加

如果需要更换远程仓库,首先删除已有的origin,然后重新添加新的远程仓库。

删除已有的远程仓库

git remote remove origin

重新添加新的远程仓库

git remote add origin https://github.com/new-repo.git

验证新的远程仓库

git remote -v

输出示例:

origin https://github.com/new-repo.git (fetch)

origin https://github.com/new-repo.git (push)

方案二:修改已有远程仓库的URL

如果只是想修改远程仓库的URL,可以使用git remote set-url命令。

修改远程仓库的URL

git remote set-url origin https://github.com/new-repo.git

验证新的远程仓库

git remote -v

输出示例

origin https://github.com/new-repo.git (fetch)

origin https://github.com/new-repo.git (push)

3. 提交代码

在成功修改或重新添加远程仓库后,可以按照正常的Git提交流程推送代码。

切换到main分支

git checkout main

拉取最新代码(避免冲突)

git pull origin main --rebase

添加修改

git add .

提交更改

git commit -m "更新代码"

推送到GitHub

git push -u origin main

转载来自:

Git报错fatal: remote origin already exists的远程仓库管理_remote origin already exists.-CSDN博客

二**、git提交到远程仓库:**

1.将本地的Git仓库与远程仓库关联

git remote add origin http://1.1.1.1/dsic/Simulator.git

2.加入暂存区(.是将文件夹内所有修改的文件、文件夹都暂存,也可以手动选择文件进行暂存)

git add .

git add -f dist

3.提交说明(-m后面是需要提交的说明)

git commit -m '提交内容说明'

4.查看当前分支

git branch

5.上传代码到分支

git push origin master

转载来自:

本地项目推送到gitlab仓库的保姆级教程_如何将本地项目上传到gitlab-CSDN博客

相关推荐
成为你的宁宁19 小时前
【基于 GitLab Webhook 的 Jenkins 自动触发构建实现手册:涵盖概念原理、环境配置、故障处理及 Tag/Commit 维度参数化构建实践】
自动化·gitlab·jenkins
邵伯正在输入19 小时前
如何同时管理GitLab/GitHub的SSH密钥
ssh·gitlab·github·intellij idea
一条懒鱼6662 天前
Jenkins 2.528.3 与 GitLab 深度集成:实现自动构建
servlet·gitlab·jenkins
爱宇阳3 天前
在 Docker 环境中为 GitLab 实例配置邮件服务器
java·docker·gitlab
爱宇阳3 天前
使用 Docker 容器备份 GitLab 实例教程
docker·容器·gitlab
爱宇阳3 天前
使用 Docker 容器备份与 Docker Compose 升级 GitLab 实例教程
docker·eureka·gitlab
初学者_xuan5 天前
Git&GitLab安装gitlab(rocky系统)
git·gitlab
凤凰战士芭比Q5 天前
DevOps理念、Git(Git常用命令)、Gitlab仓库
git·gitlab·devops
HIT_Weston6 天前
66、【Ubuntu】【Gitlab】拉出内网 Web 服务:Gitlab 配置审视(十)
前端·ubuntu·gitlab
小池先生6 天前
docker 安装gitlab
docker·容器·gitlab