Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What I can do to resolve "1 commit behind master"?

After pushing I've been seeing this message at remote repository:

1 commit behind master.

This merge has conflicts that must be resolved before it can be committed.

To manually merge these changes into TA20footerLast run the following commands:

git checkout 7c891f50c557

Note: This will create a detached head!

git merge remotes/origin/master

like image 629
Roman Yavoriv Avatar asked Dec 06 '15 14:12

Roman Yavoriv


2 Answers

Before you begin, if you are uncomfortable with a command line, you can do all the following steps using SourceTree, GitExtensions, GitHub Desktop, or your favorite tool.

To solve the issue, you might have two scenarios:


1. Fix only remote repository branch which is behind commit

Example: Both branches are on the remote side

ahead === Master branch

behind === Develop branch

Solution:

  1. Clone the repository to the local workspace: this will give you the Master branch, which is ahead with commit

    git clone repositoryUrl 
  2. Create a branch with Develop name and checkout to that branch locally

    git checkout -b DevelopBranchName // this command creates and checkout the branch 
  3. Pull from the remote Develop branch. Conflict might occur. if so, fix the conflict and commit the changes.

     git pull origin DevelopBranchName 
  4. Merge the local Develop branch with the remote Develop branch

      git merge origin develop 
  5. Push the merged branch to the remote Develop branch

      git push origin develop 

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 
like image 87
ash Avatar answered Sep 18 '22 21:09

ash


  1. Clone your fork:

  2. Add remote from original repository in your forked repository:

    • cd into/cloned/fork-repo
    • git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
    • git fetch upstream
  3. Updating your fork from original repo to keep up with their changes:

    • git pull upstream master
    • git push
like image 24
Gurdeep Singh Avatar answered Sep 20 '22 21:09

Gurdeep Singh