2

I am new to github. I have been working on a code that I fetched from github. Now I completed making my modifications and I want to push my code to github. I would like to create a fork of the original code that I worked on and push my developed code over that fork. However while I was working on development there has been some changes at the original code. So when I try to push my new code to the fork I get the following error:

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

Then I used

git pull

which outputted the following:

Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.

I can't continue from this point on. What should I do to commit my project?

polerto
  • 1,750
  • 5
  • 29
  • 50

2 Answers2

7

Well, git is telling you what to do. If you want to pull, you need to finish the incomplete merge first. Git status should tell you what files are as yet unmerged. You need to resolve the merge conflicts and then use git add on the file(s) to tell git that the conflict is resolved.

With that said, if your goal is to work off a fork, you should fork the code first, clone the forked code, make your modifications to it, and then push your changes back to the fork. Once that's done, you can submit a pull request to the authors of the original project to integrate your changes.

wadesworld
  • 13,535
  • 14
  • 60
  • 93
  • 1
    He can salvage his commits by fixing the merge, commit. Then pull his forked report into another directory and then merge from local dir to local dir. Then push to his fork. – Andrew T Finnell Jun 22 '12 at 01:27
-5

[DANGER] Dont attempt if you are working in a team

Try this.

git push -f original master 

Always saves the day...

vincent mathew
  • 4,278
  • 3
  • 27
  • 34
  • 3
    forcing a push is bad practice and you should avoid it unless you want to create some enemies :| – peshkira Jun 21 '12 at 20:51
  • I thought he is working alone and not on Kernel.org. Check this out, what happens there http://stackoverflow.com/a/432518/677185 – vincent mathew Jun 23 '12 at 04:45