git pull says up-to-date but git push rejects non-fast forward

I’ve just pulled a new branch, made some local changes, committed and tried to push. I was given this error: ! [rejected] groups -> groups (non-fast forward)
So I tried a to pull but was told Already up-to-date.

Here’s what I get pulling then pushing.

  • Can git detect a rename in which the delete occurs in a commit before the add?
  • Merging a pull request to my fork
  • Check version on remote ftp?
  • How do I find all commits that contain (not touch) a file in git?
  • Add ignored config file to git repo as sample
  • Branches have apparently diverged, but commit history is identical
  • ~/dev$ git pull origin groups
    Already up-to-date.
    ~/dev$ git push origin groups
    To /mnt/ebs/git/repo.git
     ! [rejected]        groups -> groups (non-fast forward)
    error: failed to push some refs to '/mnt/ebs/git/repo.git'
    

    Can anyone explain how this can be happening and how I can fix it?

  • Git SSH access setup issue
  • Shall I clean up the commits on my feature branch which partially undo one another?
  • How to create tag automatically in SourceTree
  • Git workflow for lone developer (total git newbie)
  • What does git update-server-info do?
  • Submodules or .gitignore for plugin repos?
  • 3 Solutions collect form web for “git pull says up-to-date but git push rejects non-fast forward”

    When you pulled the branch, did you use the “–track” option (in order to keep you local branch tracking the remote branch). If you did not, it can explain that the “merge” command that does not work.

    You can do the merge manually:

    git fetch
    git merge origin/groups
    

    To compare local and remote repos, I suggest you this command (add it in an alias, it is usefull):

    git log --graph --oneline --all --decorate
    

    It will print the project history tree, showing the branch labels. So you will see where your branch and the origin branch diverge.

    Note: if you want to preserve a linear history, instead of a “merge”, you can do a “rebase” of your local branch on the remote before pushing:

    git rebase origin/groups
    git push origin groups
    

    I came here with a different problem.

    My git was set up to push all branches. I was on a branch FOO, but it was also trying to push master, which was not up to date. The trick was noticing it was trying to push master:

    To git@git.machine:repo
     ! [rejected]        master -> master (non-fast-forward)
    

    I added the following to my .gitconfig to only push the current branch by default:

    [push]
        default = current
    

    This is not an answer to the question asked. I had a different problem with the same error message.

    My local branch did not have the remote branch to pull the changes from configured properly [git pull]. This was evident from the o/p of git remote show origin. So, I had to use git pull origin <branch_name> instead of git pull to pull the changes.

    Git Baby is a git and github fan, let's start git clone.