Git rejected updates. Pull not solving it

纵然是瞬间 提交于 2019-12-25 03:14:14

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/48915291/git-rejected-updates-pull-not-solving-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!