0

When trying to git push my changes on git, I get the following error:

To $gitRepo
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to $gitRepo
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  

No modifications have been made on this branch (I'm the only one working on it). So I really shouldn't get a non-fast-forward error.

When I do git pull, I get:

You asked me to pull without telling me which branch you
want to merge with, and 'branch.$myCurrentBranch.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

I am indeed on $myCurrentBranch, as git status confirms it.

Funnily enough, the changes are registered (checked both with git log and on the repository).

Do you have any ideas why I get these errors?

Madalina
  • 23
  • 5

2 Answers2

1

Check your .git/config file whether you've following entry in there. If not, you need to add it:

[branch "master"]
    remote = origin
    merge = refs/heads/master

This tells that, when you do a git pull on branch master, this will merge with refs/heads/master.

Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
0

For the first, did you at some point pushed your master, then rebased your local master? If you're alone on the project this might explain the error.

For the second one, you're branch does not seems to be linked to a remote one. Setting an upsteam branch might help you.

If your problem is different, can you add some commit logs of your local and remote branches so we can se a bit more clearly what's happening?

Community
  • 1
  • 1
padawin
  • 4,230
  • 15
  • 19