1

I'm trying to push to my GitHub repo. But I get the following error:

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.

I think it has to do with a /config/config.json file. This file is inside my .gitignore, but I added it for once and for all manually on the GitHub website and removed the passwords inside it. The pull command gives me this error:

The following untracked working tree files would be overwritten by merge:
        config/config.json
Please move or remove them before you can merge.

But I don't want to remove it, because it is an essential file in the repo. I read on the internet I should try push -f, but this removes that file from my repo completely. How can I push my next changes to other files, without having to worry about this config.json file?

Thanks in advance,

Erik

ErikB26
  • 27
  • 3
  • Hint. Remove the file and pull ;) – evolutionxbox Feb 21 '18 at 20:57
  • Rename `config/config.json` to `config/config.json__`. Then pull and merge. Rename back `config/config.json__` to `config/config.json` after that. And commit. (But better use rebase but it is too diffcult to explain in two words) – oklas Feb 21 '18 at 21:03

1 Answers1

0

The error tells you that the file is untracked.
Does it show as untracked when you do git status?

If so you need to do git add config/config.json followed by a commit and a push. However, if the file has changed on the remote branch you will not be able to do the push (Git will reject the updates).

In that case one solution is to rebase your local branch on the remote branch with git fetch followed by git rebase origin/branch-name

Here conflicts may appear that you need to resolve before you can push.

Oh, and before you can rebase you need to do git stash to stash your local uncommitted changes (if you have any). You can restore them after the rebase with git stash pop

Stefan R.
  • 112
  • 15