GIT "1 commit behind master"?

107 阅读1分钟

这个恼人的东西时常出现。

1. Fix only remote repository branch which is behind commit

  • ahead === Master branch
  • behind === Develop branch

Solution:

  1. Pull from the remote Develop branch. Conflict might occur. if so, fix the conflict and commit the changes.

     git pull origin dev
    
  2. Merge the local Develop branch with the remote Develop branch

      git merge origin dev
    
  3. Push the merged branch to the remote Develop branch

      git push origin dev
    

2. Local Master branch is behind the remote Master branch

This means every locally created branch is behind.

Before preceding, you have to commit or stash all the changes you made on the branch behind commits.

Solution:

  1. Checkout your local Master branch

    git checkout master
    
  2. Pull from remote Master branch

    git pull origin master
    

Now your local Master is in sync with the remote branch. As a result of the above command, other local branches branched from the previous local Master branch are not in sync. To fix that:

  1. Checkout the branch that is behind your local Master branch

    git checkout BranchNameBehindCommit
    
  2. Merge with the local Master branch

    git merge master  // Now your branch is in sync with the local Master branch
    

If this branch is on the remote repository, you have to push your changes.

    git push origin branchBehindCommit