What I can do to resolve “1 commit behind master”?

…衆ロ難τιáo~ 提交于 2019-12-02 17:10:30

I know this is a late answer but it could help others.

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

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

a head === Master branch

behind === Develop branch

Solution:

i) Clone the repository to the local workspace: this will give you the Master branch which is ahead with commit

    git clone repositoryUrl

ii) Create a branch with Develop name and checkout to that branch locally

   git checkout -b DevelopBranchName // this command creates and checkout the branch

iii) Pull from the remote Develop branch

   git pull origin DevelopBranchName

iv) Merge the local Develop branch with the remote Develop branch

     git merge origin develop 

v) 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 are behind.

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

Solution:

i) Checkout your local Master branch

   git checkout master

ii) Pull from remote Master branch

   git pull origin master

Now your local Master is in sync with the remote Branch but other local remotes are not in sync with your local Master branch because of the above command. 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 local Master branch

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

     git push origin branchBehindCommit
Gurdeep Singh
  1. Clone your fork:

    • git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git
  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

If your branch is behind by master then do:

git checkout master (you are switching your branch to master)
git pull 
git checkout yourBranch (switch back to your branch)
git merge master

After merging it, check if there is a conflict or not.
If there is NO CONFLICT then:

git push

If there is a conflict then fix your file(s), then:

git add yourFile(s)
git commit -m 'updating my branch'
git push

Use

git cherry-pick <commit-hash>

So this will pick your behind commit to git location you are on.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!