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