Pierce McGeough
Pierce McGeough

Reputation: 3086

Error trying to push a Git to remote

I have done this the wrong way but have gotten stuck.

I had a git repo I was working on and left for a while and at one stage I had to reset my machine. I forgot about the repo and was working on a new site and started using a new git. I tried to push this new local repo to the remote but got errors.

Below is the commands i used.

git init
git add .
git commit -m 'new wordpress site'
git remote add origin "url_of_previous_site"
git push

// I get the following error
// fatal: The current branch master has no upstream branch.
// To push the current branch and set the remote as upstream, use

// "git push --set-upstream origin master"
// I run that with the following message

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'url_of_previous_site'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
error: failed to push some refs to 'url_of_previous_site'

// I tried the git pull and pushed again but got the same error

Upvotes: 0

Views: 259

Answers (2)

Bernard Jesop
Bernard Jesop

Reputation: 786

You have to add and commit you work before doing a git pull. Then you fix possible conflicts. Add it, commit it again and finally push it. Now you work will be merged properly on the remote.

Upvotes: 0

Petr Skocik
Petr Skocik

Reputation: 60163

git push --force will forcibly sync your local repo to the remote (while rewriting some incompatible history on the remote -- that's why you need the force flag)

Upvotes: 1

Related Questions