-3

It seems I did something wrong:

$ git add .
$ git status
On branch master
nothing to commit, working directory clean
$ git commit -m 'Task #2 after accepting'
On branch master
nothing to commit, working directory clean
$ git push origin master
To https://my_repository@bitbucket.org/my_repository/bla.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://my_repository@bitbucket.org/my_repository/bla.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I don't know what to do to make GIT work as before and I don't remember, that I did something with git local directory except moving local repository in other folder.

Imugi
  • 151
  • 1
  • 3
  • 12
  • 2
    `git status` is showing that you have no tracked or staged files, so no changes are getting committed when you `git commit`. Additionally, the error message tells you a whole lot. There are changes on the remote repository that you don't have yet, so you need to fetch/pull those before you can push anything. – Alec Mar 11 '16 at 22:13
  • Did you even look at the error message? It tells you what to do to fix the problem! – jwodder Mar 11 '16 at 22:22
  • Possible duplicate of [What does "Git push non-fast-forward updates were rejected" mean?](http://stackoverflow.com/questions/4684352/what-does-git-push-non-fast-forward-updates-were-rejected-mean) – Roman Mar 12 '16 at 00:52
  • Possible duplicate of [git error: failed to push some refs to](http://stackoverflow.com/questions/24114676/git-error-failed-to-push-some-refs-to) – Asim K T Mar 12 '16 at 07:44

2 Answers2

2

The error message is saying that "the remote contains work that you do hint: not have locally". In order to push your commit, you should first integrate it with the rest of the project.

First of all, create a new local branch once your commit has been done:

git checkout -b task2

Then, checkout master. At this point you have to transform your current master branch (old master + 1 commit) into the new master branch (old master + changes in remote repository). In order to do so, remove the last commit from your master branch (don't worry, your changes are not going to be lost, they are referenced by task2 branch) and pull the new changes:

git checkout master
git reset --hard HEAD~1
git pull

Your master branch should look like the remote master branch. Now, go back to your task2 branch and rebase it to master in order to place your commit on top of the commit list in master:

git checkout task2
git rebase master

(Resolve conflicts if any, add files and enter git rebase --continue)

Now your task2 branch contains your commit together with all the commits in the remote server. You can now put your changes back to master again, and push your commit:

git checkout master
git merge task2
git push origin master
Bustikiller
  • 2,232
  • 1
  • 11
  • 28
2

You can force a push to your repository. Try use this command

git push -f origin master

  • 1
    This might be pretty dangerous if the state of the current branch is not what they intend. – whaleberg Dec 12 '16 at 20:20
  • Yes indeed it is really risky and dangerous if it is used by somebody who is just messing around. However this a solution that solves the problem above, and it needs to be used wisely and for terminal cases. – Old Ben Murphy Dec 12 '16 at 20:33