What I can do to resolve "1 commit behind master"?
Solution 1
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:
Clone the repository to the local workspace: this will give you the Master branch, which is ahead with commit
git clone repositoryUrl
Create a branch with Develop name and checkout to that branch locally
git checkout -b DevelopBranchName // this command creates and checkout the branch
Pull from the remote Develop branch. Conflict might occur. if so, fix the conflict and commit the changes.
git pull origin DevelopBranchName
Merge the local Develop branch with the remote Develop branch
git merge origin develop
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:
Checkout your local Master branch
git checkout master
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:
Checkout the branch that is behind your local Master branch
git checkout BranchNameBehindCommit
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
Solution 2
Clone your fork:
git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git
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
Updating your fork from original repo to keep up with their changes:
git pull upstream master
git push
Solution 3
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
Solution 4
If the message is "n commits behind master."
You need to rebase your dev branch with master. You got the above message because after checking out dev branch from master, the master branch got new commit and has moved ahead. You need to get those new commits to your dev branch.
Steps:
git checkout master
git pull #this will update your local master
git checkout yourDevBranch
git rebase master
there can be some merge conflicts which you have to resolve.
Solution 5
Suppose currently you are in your branch myBranch
Do the following :-
git status
If all changes are committed
git pull origin master
If changes are not committed than
git add .
git commit -m"commit changes"
git pull origin master
Check if there are any conflicts then resolve and commit changes
git add .
git commit -m"resolved conflicts message"
And then push
git push origin myBranch
Roman Yavoriv
Updated on February 04, 2022Comments
-
Roman Yavoriv over 2 years
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
-
Ashwani over 4 yearsGenerally, the developers don't have permission to push into master. In that case, this solution will be better: stackoverflow.com/a/59064413/8872674
-
slim over 4 yearsJust wanted to add that rebasing should only be used with private branches: blog.axosoft.com/golden-rule-of-rebasing-in-git
-
Samuel Gonçalves about 4 yearsRebase should be applied carefully since it rewrites the commits hash and can lead to some problems.
-
skdhfgeq2134 almost 4 yearsAt 1) -> 3) gives an error: Automatic merge failed; fix conflicts and then commit the result.
-
DirectedSoul about 3 yearsThank you very much, this is exactly what I needed. Works like a charm.
-
Jahanzeb Nawaz over 2 yearsplease think about keeping the commit history. deleting any commit wonts works. not a good approach.
-
Sebastian Juarez over 2 yearsworks perfectly fine, very well explained!
-
KansaiRobot over 2 yearsAlready did this, Throws error
-
charitha amarasinghe about 2 years"Everything up-to-date". I tried. I got this "Everything up-to-date". not worked for me.