Git 项目切换到新的远程仓库地址

已存在的 Git 项目切换到新的远程仓库地址,比如你要换成:

复制代码
git@github.com:baoing/test-app.git

步骤如下:

  1. 查看当前的远程仓库地址(可选)
bash 复制代码
git remote -v

你会看到类似:

复制代码
origin git@github.com:old-user/old-repo.git (fetch)
origin git@github.com:old-user/old-repo.git (push)
  1. 修改远程仓库地址为新的:
bash 复制代码
git remote set-url origin git@github.com:baoing/test-app.git
  1. 验证是否修改成功
bash 复制代码
git remote -v

你应该看到:

复制代码
origin  git@github.com:baoing/test-app.git (fetch)
origin  git@github.com:baoing/test-app.git (push)
  1. 推送到新仓库(如果需要)
    比如你想把当前所有分支推送到新仓库:
bash 复制代码
git push -u origin --all

或者只推当前分支:

bash 复制代码
git push -u origin main

(替换 main 为你当前的分支名)

如果你还没有将这个项目提交过任何内容,可以先执行:

bash 复制代码
git add .
git commit -m "Initial commit"
git push -u origin main
相关推荐
执键行天涯10 分钟前
idea中已经被git缓存追踪的文件,如何让git重新忽略
git·缓存·intellij-idea
hkhkhkhkh12336 分钟前
Git push 失败(remote unpack failed: Missing tree)解决方案
linux·git
拾贰_C2 小时前
【anaconda】anaconda安装配置,git安装配置以及pytorch安装
人工智能·pytorch·git
Just_Paranoid4 小时前
【Gerrit Patch】批量下载 Gerrit 提交的 Patch
git·gerrit·shell·patch
T - mars17 小时前
Pycharm中使用git
ide·git·pycharm
jason_yang19 小时前
Workspace搭建Vue3+组件分离的Monorepo项目
git·npm·前端工程化
鸽鸽程序猿1 天前
【Git】Git 简介及基本操作
git
ziyue75751 天前
idea终端添加git-bash,支持linux的shell语法
linux·git·bash·idea·软件
风也温柔☆2 天前
idea 拉取分支git pull报错 The branch to pull from should be selected
git·intellij-idea·debug·git pull
博闻善行2 天前
git基础操作
运维·git