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

12

117

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

Disapprobation answered 6/12, 2015 at 14:20 Comment(1)
If you want to see what that 1 new commit is on master, run git log -1 -p origin/masterCorr
A
142

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
Astatine answered 25/3, 2017 at 10:8 Comment(1)
At 1) -> 3) gives an error: Automatic merge failed; fix conflicts and then commit the result.Lattie
S
83

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
Slangy answered 25/7, 2019 at 21:53 Comment(1)
Generally, the developers don't have permission to push into master. In that case, this solution will be better: https://mcmap.net/q/187142/-what-i-can-do-to-resolve-quot-1-commit-behind-master-quotSypher
S
56
  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
Southeasterly answered 27/7, 2018 at 17:3 Comment(2)
Thank you very much, this is exactly what I needed. Works like a charm.Giraudoux
works perfectly fine, very well explained!Scaliger
S
27

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.

Sypher answered 27/11, 2019 at 6:39 Comment(3)
Just wanted to add that rebasing should only be used with private branches: blog.axosoft.com/golden-rule-of-rebasing-in-gitLodged
Rebase should be applied carefully since it rewrites the commits hash and can lead to some problems.Atherton
Already did this, Throws errorAngelikaangelina
B
6

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
Baerl answered 19/5, 2020 at 9:14 Comment(0)
H
3
  1. git checkout master
  2. git pull origin master
  3. git checkout BranchNameBehindCommit (your branch)
  4. git merge master
  5. git push origin branchBehindCommit
Headspring answered 3/2, 2022 at 15:59 Comment(1)
"Everything up-to-date". I tried. I got this "Everything up-to-date". not worked for me.Melissiamelita
S
3

simple fix

  1. clone repo to your system

    git clone repositoryUrl

  2. Go to the branch that has commits behind the master branch

    git checkout branch_name

  3. Rebase the branch to master

    git rebase -i origin/master

  4. vi code editor will open, type :wq and click enter

    :wq

  5. Finally push chages to the branch ,there won't be any commits behind now

    git push -f

Shanty answered 8/12, 2022 at 11:13 Comment(1)
this is most simple one.Kingcup
H
1

Having a look at your repository in GitHub...

Imagine the scenario in which main or master is your primary branch, and also you have another branch as dev, and your dev branch is N commits behind main or master, and there's nothing about this living in your local machine.

How to proceed...

Firstly you have to make a clone from the Github repository to your machine, however, at first, your local git doesn't have to know about your secondary branch status, only from the main or master, so Git gets only your remote label branch updated, and there are no commits yet in your local.

So, what you need is at least 1 commit, 1 push to main or master, and 1 pull back to you local.

Do NOT push anything for your dev branch else you would have 1 commit ahead and N commits behind main or master (so, conflicts)...

So, you'll need an auxiliary branch to send a Pull Request to your remote main or master.

Without further ado. How to proceed in this scenario:

Ater cloning the repository...

git checkout -b aux-branch -> it'll create and checkout the branch

Now, you have to make at least one change in order to record a first commit in you local Git, suposing you haven't anything to implement at the moment... Take the README.md file to change a letter, a space, a blank line more...

git status -> you'll see your README file was modified
git add README.md -> to add it to staged area, ready to the commit
git commit -m "modified readme file"
git push -u origin aux-branch -> it should generate a link that'll lead you to your repository to open and accept the ordered Pull Request.

I use accepting that with Rebase and Merge (the last option in green button when dropdown), after the accepting GitHub will ask you if you want to delete aux-branch... yes you want, so delete, 'cause your main or master now has this newest feature brought by aux-branch. Now back to your local (Git), proceed this following way:

git checkout main or master
git branch -D aux-branch -> to Delete in your local too\
git remote update --prune-> it makes both fetch and update to your remote.
git pull -> to receive the newest updates from remote GHub.
git checkout dev
git rebase dev main or master -> (rebase or merge)
git push -u origin dev -> climbing the updates to your remote branch

Now go to your GitHub reload the page, drop down to your dev branch you'll see your dev branch is the same as your main/master branch...

So that's it. I hope I helped you guys...

Handpick answered 28/10, 2021 at 14:14 Comment(0)
T
0

If the message says that you are 'n' commits behind master, then you can use the 'git sync' option in tortoise git. Where you will be prompted to select from the branch (target) that you want to pull your changes from. Hit 'Pull'. This will pull all the changes from remote (master/any target branch) into your development branch. After pulling, hit 'Push' to push all the synced changes from your local development branch to remote development branch on git.

Tetter answered 1/2, 2022 at 8:46 Comment(0)
T
0

In intelliJ you can do following simple steps - checkout your branch and pull latest commits from main/branch name Merge those changes in your branch . - > vcs -> git -> merge changes (origin/main)

push your branch to remote

This should make your branch same as target

Tade answered 23/3, 2022 at 20:7 Comment(2)
Anagha, kindly improve your answer by adding proper commandsStagecoach
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Nitroparaffin
C
0

If the behind branch is local and you want to update it with the remote master branch you can do it easily using GitHub Desktop:

  1. Choose the local branch as the current branch
  2. Go to branch menu and click on Update from master
  3. Go to Repository menu and click Push
Coadjutant answered 17/3 at 9:34 Comment(0)
S
-4

If the branch is behind master, then delete the remote branch. Then go to local branch and run :

git pull origin master --rebase

Then, again push the branch to origin:

git push -u origin <branch-name>
Shope answered 8/1, 2020 at 7:11 Comment(1)
please think about keeping the commit history. deleting any commit wonts works. not a good approach.Grilled

© 2022 - 2024 — McMap. All rights reserved.