Update were rejected because the remote contains work that you do

Update were rejected because the remote contains work that you do

Github «Updates were rejected because the remote contains work that you do not have locally.»

hint: Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing to the same ref. You may want to first merge the remote changes (e.g., hint: ‘git pull’) before pushing again.

This doesn’t seem to make sense since it’s a new repo and contains only a readme file.

11 Answers 11

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

This happens if you initialized a new github repo with README and/or LICENSE file

Now you will be able to push your repository to github. Basically, you have to merge those new initialized files with your work. git pull fetches and merges for you. You can also fetch and merge if that suits you.

The error possibly comes because of the different structure of the code that you are committing and that present on GitHub. It creates conflicts which can be solved by

Merge conflicts resolving:

If you confirm that your new code is all fine you can use:

If this is your first push

just change the

change it like this!

You may refer to: How to deal with «refusing to merge unrelated histories» error:

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

The supplied answers didn’t work for me.

I had an empty repo on GitHub with only the LICENSE file and a single commit locally. What worked was:

Also before merge you may want to:

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

I manually edited a couple files directly in the repo after I had pushed the last commit and got the same error as a result.

Would only recommend doing this though if you know exactly what was changed in the repo and you’re 100% confident you want the local commit to replace everything. Mine was a hobby project that no one else is working on and no other commits had been made from any other devices aside from the manual changes.

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

I followed these steps:

Pull the master:

This will sync your local repo with the Github repo. Add your new file and then:

Commit the changes:

Finally, push the origin master:

Refresh your Github repo, you will see the newly added files.

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

If you are using Visual S2019, Create a new local branch as shown in following, and then push the changes to the repo.

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

The issue is because the local is not up-to-date with the master branch that is why we are supposed to pull the code before pushing it to the git

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

Simply run this commands:

This can also happen if you have a shallow clone. In that case it is technically always true that “the remote contains work that you do not have locally,” because you have a limited set of commits while the remote likely has the complete history. If the local repo only has a single new commit—which can happen on CI systems—then there this causes problems as there are no commits in common and git will be unable to push.

One solution can be to perform a less-shallow clone.

Not the answer you’re looking for? Browse other questions tagged github or ask your own question.

Linked

Related

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

I’m using Visual Studio 2019 and the github updating is done thru the menu not a command line. I got an error last week when I tried to push my commits that said:

rejected Updates were rejected because the remote contains work that you do not have locally

To fix, I went to github.com and renamed the project. I was able to push several updates but now I’m getting the error again.

I am the only one using this project and the project is private so how is this possible?

2 Answers 2

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

There are multiple ways to solve this.

git clone the remote repo, making a new local repo that includes all of the new changes.

Note, changing certain things in github will cause it to create a new commit, and therefore changing the history.

This is possible because of the corruption of the repo and some bad commit/push while files have been modified online directly on GitHub (README.md for example): this causes «spaghetti«.

From the root folder of the project, you need to Fetch and Pull.

Now you should be able to Push.

You can try again to Pull and Fetch in case of problems.

If it persists, you can try this which helps me to resolve such issue quickly:

You can take a look at TortoireGit for easy, fast and advanced management with File Explorer integration having icons.

You can combine it with the TGit addon for Visual Studio.

There is also the Total Commander x64 plugin WDX GitCommander that can for example display the current branch and last commit in columns.

Updates were rejected because the remote contains work that you do not have locally

I’m working on a team with a few developers using git on BitBucket. We are all working on a dev branch, not pushing to master until a release.

One of the developers committed incorrect code that overwrote my own by accident, and now I am trying to push the correct code back to the repo. I have been reading about this error for a few days now, I can’t push to the repo anymore because I am getting the following error:

It is really frustrating, I really want to help out my team and contribute, but I can’t because of this error. Does anyone know how to solve this issue? I would very much appreciate any help.

These are the commands I run in order to commit if it helps anyone out:

I would have thought that if I kept this order, I would not receive merge conflicts. I guess I was wrong. Thanks again

Update: I should add that I have looked for a few hours on Google and StackOverflow, and followed different instructions, but I still can’t push to the dev branch.

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

21 Answers 21

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

You can override any checks that git does by using «force push». Use this command in terminal

as we have not taken updated remote in our local environment. So Take pull first from remote

It will update your local repository and add a new Readme file. Then Push updated changes to remote

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

git pull master:dev will fetch the remote/master branch and merge it into your local/dev branch.

git pull dev will fetch the remote/dev branch, and merge it into your current branch.

This usually happens when the repo contains some items that are not there locally. So in order to push our changes, in this case we need to integrate the remote changes and then push.

So create a pull from remote

Then push changes to that remote

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

I fixed it, I’m not exactly sure what I did. I tried simply pushing and pulling using:

git pull dev instead of git pull master:dev

Hope this helps out someone if they are having the same issue.

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

You need to input:

This is how I solved this issue:

This usually happens when your remote branch is not updated. And after this if you get an error like «Please enter a commit message» Refer to this ( For me xiaohu Wang answer worked 🙂 )

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

git push origin master

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

Well actually github is much simpler than we think and absolutely it happens whenever we try to push even after we explicitly inserted some files in our git repository so, in order to fix the issue simply try..

Note: if you accidently stuck in vim editor after pulling your repository than don’t worry just close vim editor and try push 🙂

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

I have done below steps. finally it’s working fine.

Steps

2) git status (for checking status)

5) git remote add origin «

The best option for me and it works and simple

this will help incase you have some changes not yet registered on your local repo. especially README.md

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

I had this error and it was because there was an update on the server but SourceTree was not showing any updates available (possibly because I was offline when it last checked). So I did a refresh in source tree and now it shows 2 items to push instead of 1 item.

So be sure to press refresh or pull if you get this error and then try again.

The error possibly comes because of the different structure of the code that you are committing and that present on GitHub. You may refer to: How to deal with «refusing to merge unrelated histories» error:

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

I had the same problem. Make sure that you are on the right heroku account. It appears when I tried to push the changes to the wrong heroku account

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

If you have initialized a new github repo with ReadMe file and also receiving a fatal error like this:

fatal: refusing to merge unrelated histories

then you probably want to give a try to the command below:

Now you can try pushing your project to your new repository:

Note: If you have initialized repository in Github and also committed locally, then you need to use the suggested command above, the first command «git pull origin. «. Otherwise you can simply type the following command:

Hope it was helpful.

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

1.git pull origin

2.accept the changes depending upon your requirement, like keeping incoming or keeping existing changes.

5.git push origin

This has worked to me. Let me know if it didn’t work to you.

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

You could simply and safely revert the changes made by your colleague. using the git revert command.

hash can be found with the following command.

It’s not ideal to revert a commit, in fact, it is a really rare case to do so. what happens often is that developers would work concurrently on similar files and do changes that are divergent. git is built in order to mitigate the amount of effort required to maintain a healthy codebase.

on top of git, services like Github, Atlassian, GitLab and possibly others provide handy interfaces and feature to reduce even more issues like that. Preventing direct push to a shared branch for example and replacing them by pull request using sub-branches instead.

If you’re team lack a little organization. my suggestion for you is to work faster in order to push breaking changes before others. (jk)

Enough of my monologue, there are a few methods that I like to use when this problem occurs.

First, and obvious one, try to fix the conflict before pushing your changes. IDEs nowadays have really nice interface for conflicts this is an example on vs-code.

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

there are a couple of apparent buttons «Accept current, incoming, both» which will let you select which piece of code you want to keep, modify or remove. you can also edit the code manually if you wish! without the IDE consent of course.

This is great, for when your work is in progress and you actually need the changes made by your teammates. Or when you’re done and you just want to land a PR before heading to bed after your third overtime.

you could do the same things via cmd, but you might end up bald by the end of the process.

If you’re working on a large feature and you’ve done lots of changes but you want to keep your files uncommitted because it’s handy sometimes to do so. stashing is your friend.

pulling a branch in between stash operations will not trigger conflict assuming your branch is close to the shared one. otherwise, you’re back at step one.

My third and final little secret are diff files.

What it basically does is that it compares the difference between two branches and creates a file called changes.diff it will show all the changes made by your colleague and will help you decide what to keep or remove

How to Fix the Remote ‘updates were rejected’ Git Error

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

The Git error “updates were rejected because the remote contains work that you do not have locally” is triggered when you initialize a new Github repo with a readme file or a license. This article dives into the solutions to this error so new updates from local machines can be pushed into the Github repository.

Possible Solutions

Sometimes a simple pull from the origin repo branch to the local project to obtain the missing files before a push is all one needs to fix the error. Assuming the branch is the master branch, the below commands will suffice.

To communicate to outside repositories, Git uses the word “remote”. By adding an address we are telling git how to reach a certain repo.

81% of participants stated they felt more confident about their tech job prospects after attending a bootcamp. Get matched to a bootcamp today.

Find Your Bootcamp Match

The average bootcamp grad spent less than six months in career transition, from starting a bootcamp to finding their first job.

Start your career switch today

The final possible solution is to fetch from the remote, send from the local, and attempt to merge the two.

Conclusion

The Git error “updates were rejected because the remote contains work that you do not have locally” is triggered when we initialize a new Github repo with a readme file or a license. Errors like this are also common when trying to get to repositories who began their lives independently, to communicate with each other. Using a few commands to help override this issue can help the local and remote repos communicate.

Как исправить ошибку GIT

hint: 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

Репозиторий на GitHub был только что создан и там нет никаких изменений

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

2 ответа 2

У вас есть там изменения, которых нет в локальном репозитории. Вы сделали не пустой репозиторий на Github, а с начальным коммитом. У локального репозитория свой первый коммит и эти коммиты, как вы понимаете, не равны (фактические у вас просто два разных репозитория).

У меня была такая же ошибка, когда я сначала создал локальный репозиторий. Потом перешел на ГитХаб и создал новый репозиторий там. Затем выполнил

А когда попробовал сделать push/pull, получил ту же fatal: unrelated_histories ошибку. И вот как я поправил это:

Update were rejected because the remote contains work that you do. Смотреть фото Update were rejected because the remote contains work that you do. Смотреть картинку Update were rejected because the remote contains work that you do. Картинка про Update were rejected because the remote contains work that you do. Фото Update were rejected because the remote contains work that you do

Всё ещё ищете ответ? Посмотрите другие вопросы с метками git или задайте свой вопрос.

Похожие

Подписаться на ленту

Для подписки на ленту скопируйте и вставьте эту ссылку в вашу программу для чтения RSS.

Нажимая «Принять все файлы cookie» вы соглашаетесь, что Stack Exchange может хранить файлы cookie на вашем устройстве и раскрывать информацию в соответствии с нашей Политикой в отношении файлов cookie.

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *