Git:开始新的本地分支

Git:开始新的本地分支,git,branching-and-merging,Git,Branching And Merging,我是git的新手 在工作中,我们有一个远程存储库,在推送备份之前,我会拉它在本地进行更改 我只是想确认我的工作流程是正确的 git fetch获取对origin/master的所有更改 git签出-b newbranch原始/主 git合并源/主(当我在当前分支上工作时) 这是我一直在做的工作过程,但我不断遇到这个恼人的错误: error: failed to push some refs to 'ssh://xxxxx' hint: Updates were rejected because

我是git的新手

在工作中,我们有一个远程存储库,在推送备份之前,我会拉它在本地进行更改

我只是想确认我的工作流程是正确的

  • git fetch获取对origin/master的所有更改
  • git签出-b newbranch原始/主
  • git合并源/主(当我在当前分支上工作时)
  • 这是我一直在做的工作过程,但我不断遇到这个恼人的错误:

    error: failed to push some refs to 'ssh://xxxxx'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
    hint: before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    
    我决定这是因为我的工作方式


    请帮忙

    git fetch命令将提交从远程存储库导入本地repo

    结果提交存储为远程分支,而不是您一直使用的普通本地分支

    这使您有机会在将更改集成到项目副本之前查看更改

    $ git pull <remote>
    
    $git pull
    
    获取当前分支的指定远程副本,并立即将其合并到本地副本中。这与
    git fetch
    后跟
    git merge origin/
    相同

    $git pull--重新基址
    

    与上面的命令相同,但是不要使用
    git merge
    来集成远程分支和本地分支,而是使用
    git rebase

    您应该检查远程分支和本地分支的状态。为此

  • git获取源
  • git log newbranch--不是源代码/主代码。 此命令应显示尚未推送到中心repo的本地提交
  • git日志源/主--不是newbranch。这将显示在源代码/主代码中但尚未合并到newbranch中的提交
  • 如果步骤3显示smth,则将源站/主站合并到新牧场
  • 重复步骤1-4,直到步骤3给出空输出(在origin/master中没有未合并到newbranch的提交)
  • 再次推送:git推送原点newbranch:master

  • git pull首先从远程repo获取代码,并通过合并来更新本地repo

    git pull origin master
    
    提交更改后,必须先执行拉操作,然后再推动更改。任何冲突都应手动解决。 在处理新分支时,首先将其与主分支合并,同时保留在该分支上

    $git branch 
    newbranch
    $git pull origin master 
    This will update your new branch with master changes and both the branches are at same state
    
    现在,
    $git checkout master
    然后
    git merge newbranch
    这将合并新牧场和主人


    我建议您参考了解git。

    从origin获取只是获取。您必须将更改合并到本地主机中。正如我从我的git体验中回忆的那样。是的,这就是我认为git合并origin/master会做的。我应该改做拉吗?git-pull-origin/masterpull=fetch+merge。可能有人在您执行本地工作(提交更改、将更改与上游合并等)时推动了另一次提交?@MarcoSusilo:是的,您需要对您的工作分支执行git-pull。您的工作分支应该是干净的,没有未提交的更改。如果您有一些未提交的更改,您可以提交或隐藏它,然后稍后应用。
    $git branch 
    newbranch
    $git pull origin master 
    This will update your new branch with master changes and both the branches are at same state