score:240

Accepted answer

i had this same problem and i was able to fix it. afk5min was right, the problem is the branch that you pulled code from has since changed on the remote repository. per the standard git practices(http://git-scm.com/book/en/git-basics-working-with-remotes), you need to (now) merge those changes at the remote repository into your local changes before you can commit. this makes sense, this forces you to take other's changes and merge them into your code, ensuring that your code continues to function with the other changes in place.

anyway, on to the steps.

  1. configure the 'fetch' to fetch the branch you originally pulled from.

  2. fetch the remote branch.

  3. merge that remote branch onto your local branch.

  4. commit the (merge) change in your local repo.

  5. push the change to the remote repo.

in detail...

  1. in eclipse, open the view 'git repositories'.

  2. ensure you see your local repository and can see the remote repository as a subfolder. in my version, it's called remotes, and then i can see the remote project within that.

  3. look for the green arrow pointing to the left, this is the 'fetch' arrow. right click and select 'configure fetch'.

  4. you should see the uri, ensure that it points to the remote repository.

  5. look in the ref mappings section of the pop-up. mine was empty. this will indicate which remote references you want to fetch. click 'add'.

  6. type in the branch name you need to fetch from the remote repository. mine was 'master' (btw, a dropdown here would be great!!, for now, you have to type it). continue through the pop-up, eventually clicking 'finish'.

  7. click 'save and fetch'. this will fetch that remote reference.

  8. look in the 'branches' folder of your local repository. you should now see that remote branch in the remote folder. again, i see 'master'.

  9. right-click on the local branch in the 'local' folder of 'branches', which is named 'master'. select 'merge', and then select the remote branch, which is named 'origin/master'.

  10. process through the merge.

  11. commit any changes to your local repository.

  12. push your changes to the remote repository.

  13. go have a tasty beverage, congratulating yourself. take the rest of the day off.

score:-2

  1. go in github an create a repo for your new code.
  2. use the new https or ssh url in eclise when you are doing the push to upstream;

score:0

i have found that you must be on the latest commit of the git. so these are the steps to take: 1) make sure you have not been working on the same files, otherwise you will run into a dity_work_tree error. 2) pull the latest changes. 3) commit your updates.

hope this helps.

score:0

in my case i forgot to pull the new changes from git

  1. right click on the project fetch from upstream
  2. right click on the project pull
  3. right click on the project push to upstream

score:3

open git view :

1- select your project and choose merge 2- select remote tracking 3- click ok

git will merge the remote branch with local repository

4- then push

score:3

this error means that remote repository has had other commits and has paced ahead of your local branch.
i try doing a git pull followed by a git push. if their are no conflicting changes, git pull gets the latest code to my local branch while keeping my changes intact.
then a git push pushes my changes to the master branch.

score:4

configure after pushing the code when you get a rejected message, click on configure and click add spec as shown in this picture

source ref and destination ref drop down and click on the ref/heads/yourbranchname and click on add spec again

enter image description here make sure you select the force update

enter image description here finally save and push the code to the repo

score:7

applicable for eclipse luna + eclipse git 3.6.1

i,

  1. cloned git repository
  2. made some changes in source code
  3. staged changes from git staging view
  4. finally, commit and push!

and i faced this issue with egit and here is how i fixed it..

yes, someone committed the changes before i commit my changes. so the changes are rejected. after this error, the changes gets actually committed to local repository. i did not want to just pull the changes because i wanted to maintain linear history as pointed out in - in what cases could `git pull` be harmful?

so, i executed following steps

  1. from git repository perspective, right click on the concerned git
    project
  2. select fetch from upstream - it fetches remote updates (refs and objects) but no updates are made locally. for more info refer what is the difference between 'git pull' and 'git fetch'?
  3. select rebase... - this open a popup, click on preserve merges during rebase see why
    what exactly does git's "rebase --preserve-merges" do (and why?)
  4. click on rebase button
  5. if there is/are a conflict(s), go to step 6 else step 11
  6. a rebase result popup would appear, just click on ok
  7. file comparator would open up, you need to modify left side file.
  8. once you are done with merging changes correctly, goto git staging view
  9. stage the changes. i.e. add to index
  10. on the same view, click on rebase-> continue. repeat 7 to 10 until all conflicts are resolved.
  11. from history view, select your commit row and select push commit
  12. select rebase commits of local....... checkbox and click next. refer why - git: rebase onto development branch from upstream
  13. click on finish

note: if you have multiple local repository commits, you need to squash them in one commit to avoid multiple merges.

score:12

in the meantime (while you were updating your project), other commits have been made to the 'master' branch. therefore, you must pull those changes first to be able to push your changes.

score:20

in my case i chose the force update checkbox while pushing. it worked like a charm.


Related Query

More Query from same tag