git 修改仓库地址并推送到远程服务器

Git 2020-04-18 阅读 85 评论 0

问题描述

公司使用自己服务器搭建 git 服务器来管理公司的开发代码,有时候换了服务器,或者 服务器的 ip 变了,就需要迁移 git 的工程代码。

解决方法

只需2步,就能完成代码的迁移。

1. 在新的服务器上,新建一个空的 git 仓库,可以使用命令 git init --bare --shared REPOSITORY.git

2. 修改本地的远程仓库地址。必须保证本地的代码是最新的。

打开终端,查看原来的远程仓库地址

$ git remote -v
origin  ssh://USERNAME@org.github.com/REPOSITORY.git (fetch)
origin  ssh://USERNAME@org.github.com/REPOSITORY.git (push)

更换本地仓库的远程服务器地址

$ git remote set-url origin ssh://USERNAME@new.github.com/REPOSITORY.git

查看现在的仓库 url。

$ git remote -v
# Verify new remote URL
origin  ssh://USERNAME@new.github.com/REPOSITORY.git (fetch)
origin  ssh://USERNAME@new.github.com/REPOSITORY.git (push)

最后,使用 git push --all 命令,将本地所有分支信息,推送到远程 git 服务器。

最后更新 2020-06-15
MIP.watch('startSearch', function (newVal, oldVal) { if(newVal) { var keyword = MIP.getData('keyword'); console.log(keyword); // 替换当前历史记录,新增 MIP.viewer.open('/s/' + keyword, {replace: true}); setTimeout(function () { MIP.setData({startSearch: false}) }, 1000); } }); MIP.watch('goHome', function (newVal, oldVal) { MIP.viewer.open('/', {replace: false}); });