Ahmed
Ahmed

Reputation: 87

"non-fast-forward updates were rejected" when trying to push remote branch

I have a remote project in projects/my_project

in my local host i'm in my_project

when trying to push my changes using git push origin master

this error appears to me

To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.

i need to push to my_project not projects .

Upvotes: 0

Views: 1273

Answers (3)

Dave
Dave

Reputation: 3623

You should not specify "master" unless you are trying to push to the remote master branch;

Try:

git push --set-upstream projects my_project

This makes the assumption that when you say "projects/my_project" you are referring to a branch called "my_project" on the remote called "projects".

The --set-upstream set up you current "my_project" branch to track the remote "projects/my_project" branch so you don't need to specify it explicitly every time.

Upvotes: 1

Tamby Kojak
Tamby Kojak

Reputation: 2159

In my experience, this problem happens because there are changes on the server that you have not pulled to your machine yet. Try doing a pull, fixing any conflicts (if any), and then committing and pushing again.

I would also recomend using something like SourceTree if you are new to git.

Here's the link: http://www.sourcetreeapp.com/

Cheers,

Upvotes: 0

Jason Baker
Jason Baker

Reputation: 2481

You have upstream changes. You have two options:

  • Execute git pull origin master, resolve any conflicts, and then re-push
  • Execute git push -f origin master. This will totally overwrite the history in your remote repository, so DO NOT do this unless you're absolutely sure.

Upvotes: 1

Related Questions