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博客

相关推荐
Byron Loong12 小时前
GitLab 全部权限角色详解
gitlab
Cat_Rocky13 小时前
Gitlab安装与配置
linux·运维·gitlab
D4c-lovetrain18 小时前
CentOS9 GitLab 完整配置全流程
gitlab
puamac19 小时前
GitLab CI/CD 故障排查手册
ci/cd·gitlab
Aubrey-J2 天前
老版本Gitlab SSL证书自动续期错误KeyError: key not found: “token“解决
网络协议·gitlab·ssl
java_logo3 天前
Docker 部署 GitLab CE 完整版教程
docker·容器·gitlab·gitlab docker部署·gitlab部署文档·gitlab部署·gitlab部署教程
隔窗听雨眠4 天前
GitLab CI前端加载慢优化实录
ci/cd·gitlab
东北甜妹6 天前
DevOps 和 Git,Gitlab
git·gitlab·devops
qq_白羊座6 天前
GitLab CI + Jenkins 双流水线模式Jenkins 端配置
ci/cd·gitlab·jenkins
qq_白羊座6 天前
GitLab CI 与 Jenkins
ci/cd·gitlab·jenkins