当前位置:   article > 正文

git本地仓库关联远程仓库_git 安装成功后关联远程库命令

git 安装成功后关联远程库命令

首先,本地文件之前是svn管理,现在直接换成git,远程仓库已经有新代码和master分支

  1. 初始化 git init
  2. 关联远程仓库   git remote add origin https:....git(换成远程仓库地址)
  3. git branch -a 查看目前有哪些远程分支
  4. 拉取远程的master分支 git pull origin master     ,此时报错 error: The following untracked working tree files would be overwritten by merge:   本地有多个文件与远程仓库不一致,不能直接使用  git reset --hard HEAD 因为目前还不在哪个分支
    fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.也不能直接使用切换分支 git checkout -b master origin/master 
    error: The following untracked working tree files would be overwritten by checkout:
            .babelrc .js   Aborting
  5. 此时先贮藏目前的差异文件  git add . 添加全部差异文件;

     $ git stash -a -m 'svn' 
    You do not have the initial commit yet  

    0@DESKTOP-2RBCSD9 MINGW64 /d/newFrontProject (master)
    $ git commit
    [master (root-commit) 9ddb6f8] nit svn   (查看状态)$ git status
    On branch master
    nothing to commit, working tree clean

  6. 再次查看git branch -a并且拉取$ git pull origin master,发现出现merge conflict;(master|REBASE 1/1)
    $ git status
    interactive rebase in progress; onto 1245feb

  7. 查看所在分支会发现是rebase状态,也就不在master分支上 :

     (master|REBASE 1/1)
    $ git branch
    * (no branch, rebasing master)
      master

    0@DESKTOP-2RBCSD9 MINGW64 /d/newFrontProject/DossierSite/WebSiteForManager (master|REBASE 1/1)
    $ git reset --hard HEAD(不想直接丢弃本地差异文件可以再次使用前面步骤5进行贮藏)
    HEAD is now at 1245feb Merge #1 into master from dev1

  8. 使用rebase命令:(master|REBASE 1/1)
    $ git rebase --continue
    Successfully rebased and updated refs/heads/master.

  9. 再次拉取master分支,此时状态正常,拉取成功:

     (master)
    $ git pull origin master --rebase
    From https://
     * branch            master     -> FETCH_HEAD
    Already up to date.

  10. 查看所在分支已正常:(master)
    $ git branch
    * master (*表示目前在这个分支上)

  11. 此时直接git pull 拉取代码会提示没有关联远程分支:

     (master)
    $ git pull
    There is no tracking information for the current branch.
    Please specify which branch you want to rebase against.
    See git-pull(1) for details.

        git pull <remote> <branch>

    If you wish to set tracking information for this branch you can do so with:

        git branch --set-upstream-to=origin/<branch> master
     

  12. 使用命令:(master)
    $ git branch --set-upstream-to=origin/master master
    提示 Branch 'master' set up to track remote branch 'master' from 'origin'.

  13. 使用 git pull正常,不需要指定分支
    Already up to date.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/460092
推荐阅读
相关标签
  

闽ICP备14008679号