-1

I've trying to push my files into git, but it doesn't work.

This is what I've done before.

git init
git add .
git commit -m "Start"
git remote add origin git@github.com:user/repo.git 

The first git push -u origin master works.

After changing some files and trying to git push -u origin master again it doesn't work.

To git@github.com:denis89/gaw8d3.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:denis89/gaw8d3.git'
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.

Also git pull doesn't work, because of unmerged files. Any ideas?

guntbert
  • 536
  • 6
  • 19
Denis Doan
  • 73
  • 1
  • 8
  • 4
    I've found out how to resolve it thanks to Trev Norris: http://stackoverflow.com/questions/15127078/git-pull-is-not-possible-unmerged-files – Denis Doan Sep 30 '15 at 22:07

1 Answers1

1

You will not be able to push because your head is behind the remote thus the non-fast-forward message. You must perform a git pull before you can push. A git pull actually performs a git fetch and then a git merge.

You say git pull does not work because of un-merged files. This is most likely caused by one of two things:

  1. conflicts. If you have conflicts you need to resolve them and then commit locally to merge.

  2. you have uncommitted files that are conflicting with files you are attempting to pull.

In the second case you can't pull because the remote has a more up to date version of a file you have made changes to but have not committed your version and so git cannot even attempt to merge the versions.

You will have commit your version of this file and then try to merge again. If you don't want to commit those files you must stash them before you can pull.

In both cases a simple git status command will show you committed files uncommitted files and conflicts.

GrandMasterFlush
  • 6,269
  • 19
  • 81
  • 104
rickmaster
  • 161
  • 1
  • 8
  • I've found out how to resolve it thanks to Trev Norris: http://stackoverflow.com/questions/15127078/git-pull-is-not-possible-unmerged-files – Denis Doan Sep 30 '15 at 22:07
  • Yes a hard reset would reset your git branch to the checked out head and then allow you to pull but you lose any local changes. – rickmaster Oct 01 '15 at 17:36