0

Edit:

Everybody able to read should recognize, that I did not ask about how to resolve the problem I described (because I read what to do about this error pretty often but was unable to understand the solution), but which well-known name to pass to

git diff

in order to create the correct patch.

end edit

I cannot push into the remote repo because of some recurring reason, which (for me) makes working with branches impossible with git:

error: failed to push some refs to 'user@machine:/directory'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally.

So I decided to create some patch file and apply this patch in some clean directory. But I don't have any clue what well-known object name stands for Starting-branch-of-Branch-A in order to make certain, that I'm getting the correct patch. So what argument do I have to pass to

git diff

?

  • 5
    I think git is letting you know that you should fetch from the other repo and merge/rebase so that you can get what is on the other branch and your local branch together so that you can then push your branch into the remote. – eftshift0 Oct 17 '18 at 20:55
  • Possible duplicate of [git: updates were rejected because the remote contains work that you do not have locally](https://stackoverflow.com/questions/24357108/git-updates-were-rejected-because-the-remote-contains-work-that-you-do-not-have) – phd Oct 18 '18 at 14:30
  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+remote+contains+work+that+you+do – phd Oct 18 '18 at 14:30
  • everybody: read the question –  Oct 25 '18 at 14:01

2 Answers2

0

You're ahead of your remote repo. One way is save your local work somewhere else and reset your current repo to remote's head using following

git reset --hard HEAD

Caution : this command will erase whatever you've worked and saved locally

after resetting to HEAD use following command

git pull origin master

At this step you are sync with remote repo. Now you can replace your saved work on your local branch and the rest is easy.

git add .
git commit
git push origin master
Vahid Hashemi
  • 5,182
  • 10
  • 58
  • 88
0

One common way to resolve this would be to first run git fetch (or git fetch origin in case you want to fetch a specific remote, or git fetch --all to fetch all remotes). This does not affect your working directory, your branch or anything that could be relevant to you, so you can run that command anytime you like. This will update the remote tracking branches in your repo, usually named <remote>/<branch>, e.g. origin/master.

Now you can check your Git log, for example with git log --color --all --decorate --oneline --graph, or some GUI tool (e.g. gitk --all). It will show you how your branch, in your current case, diverged from the remote branch. You can then decide whether you want to merge your branch and the remote branch (e.g. with git pull) or rebase your branch ontop of the remote branch (e.g. git pull --rebase).

alfunx
  • 3,080
  • 1
  • 12
  • 23
  • I should perform a fetch in order to get the correct patch? –  Oct 25 '18 at 14:00
  • If you insist on using patches instead of what Git natievly offers, you can use `git merge-base --fork-point ` to find ``, where `` was branched off of ``, and then run `git diff HEAD`. – alfunx Oct 25 '18 at 14:33