Joyeuxman / Joyeuxman.github.io

个人博客
1 stars 0 forks source link

Git远程仓库地址修改后你需要如何做 #12

Open Joyeuxman opened 5 years ago

Joyeuxman commented 5 years ago

Git远程仓库地址修改后你需要如何做

  1. 查看本地现在的远程仓库地址

    git remote -v 
    
    //output
    origin http://xxx.xxx.old.git
  2. 删除本地现在的远程仓库地址

      git remote rm origin
  3. 验证本地现在的远程仓库地址是否删除成功

      git remote -v  
    
      //没有出现origin,表示删除成功
  4. 将新的远程仓库地址添加到本地

      git remote add origin http://xxx.xxx.new.git
  5. 验证新的的远程仓库地址是否添加成功

      git remote -v   
    
      //output
      origin http://xxx.xxx.new.git //出现origin内容表示添加成功
  6. 获取新的远程分支

      git fetch origin   
    
      //output
      From http://xxx.xxx.new.git
      * [new branch]        newBranch1     -> origin/newBranch1
      * [new branch]        newBranch2     -> origin/newBranch2
      * [new branch]        newBranch3     -> origin/newBranch3
  7. 查看所有的分支(本地旧分支+远程仓库新分支)

      git branch -a   
    
      //output
      oldBranch1
      oldBranch2
      oldBranch3
      remotes/origin/newBranch1
      remotes/origin/newBranch2
      remotes/origin/newBranch3
  8. 依次删除本地旧分支

      git branch -d oldBranch1  
      git branch -d oldBranch2
      git branch -d oldBranch3
    
      //or 强制删除
      git branch -D oldBranch1  
      git branch -D oldBranch2
      git branch -D oldBranch3
    
      // output
      Deleted branch oldBranch1
      Deleted branch oldBranch2
      Deleted branch oldBranch3
  9. 查看删除本地旧分支是否成功

      git branch -a   
    
      //output   success
      remotes/origin/newBranch1
      remotes/origin/newBranch2
      remotes/origin/newBranch3
  10. 切换远程新分支b并创建对应的本地分支

      // 格式 git checkout -b 本地分支名 远程分支名
      git checkout -b newBranch1 remotes/origin/newBranch1
      git checkout -b newBranch2 remotes/origin/newBranch2
      git checkout -b newBranch3 remotes/origin/newBranch3
    
      //output   success
      Switched to a new branch 'uat'
      Branch 'newBranch1' set up to track remote branch 'newBranch1' from 'origin'.
      ...
  11. 查看本地新分支是否创建成功

      git branch -a   
    
      //output   success
      newBranch1
      newBranch2
      newBranch3
      remotes/origin/newBranch1
      remotes/origin/newBranch2
      remotes/origin/newBranch3
  12. 拉取最新代码

      git pull