Updates were rejected because the remote contains work that you do git

Updates were rejected because the remote contains work that you do git

Cannot push my project to an existing Github repository: «Updates were rejected because the remote contains work that you do not have locally»

After reading the Github documentation, I wanted to push all of my previously done local projects to a pre-existing repository.

For a folder like this:

I wanted to push it to a repository named «practice» such that project_abc lies inside it.

But I stumbled across errors on my very first such folder.

1 Answer 1

Your basic error is that you are conflating project and repository here.

Some people do like to put multiple (albeit usually related ) projects into a single repository. The jargon term for this is monorepo: a monorepo stores all those projects in one Git repository (in this, Git’s, case; but other version control systems often work very similarly), which makes many things more convenient, and some other things less convenient. The linked Wikipedia page has a decent overview.

To put multiple projects into a monorepo, you make the one repository—i.e., run git init once—and then organize everything into that one repository. You can then clone that repository to make your distributed copies of that repository, using git clone and git fetch and git push as appropriate (see below).

What to know before you start

Git is a distributed version control system, or DVCS. A version control system holds versions (of files). These come in many flavors, and lately the usual distinction is distributed versus centralized. A centralized VCS has an authoritative «this is the correct one» location: there might be additional copies, but only the central VCS has the «real» copies. A distributed VCS lacks this central control point: each DVCS is «the real copy» even if they’re all slightly different.

As with monorepo vs polyrepo, CVCS vs DVCS offers advantages and disadvantages. We won’t try to cover those here since you’ve already chosen the DVCS.

Git in particular stores versions as commits. Commits are Git’s raison d’être and a repository is mainly just a big database of commits. However, each commit in a Git repository is found by a very large, random-looking number, expressed in hexadecimal as a big ugly hash ID. These are impossible for humans to remember and to deal with, so Git provides a second database of names: branch names, tag names, remote-tracking names, and all kinds of other names. A Git repository will use its secondary names database to remember the raw hash IDs for you, so that you can use human-oriented names to extract your versions.

A Git repository is therefore really two databases:

The big database contains commits, and other supporting Git objects. These are numbered (with big ugly hash IDs); Git needs the hash IDs in order to use this database.

The smaller (usually much smaller) database contains names, which you (a human) will use to have Git find the hash IDs so that Git can find the commits in the (usually much bigger) objects database.

Each commit’s unique number lets Git extract that one particular commit later. Every commit stores two things:

Each commit has a full snapshot of every file, frozen in time in the form it had when you (or whoever) made the snapshot. To save space, these are stored in a special, read-only, Git-only, compressed and de-duplicated format. Only Git can read them, and literally nothing, not even Git itself, can overwrite them. But this makes them almost useless, except as we’ll see below.

Each commit also has some metadata, or information about that particular commit. This includes stuff like the name and email address of whoever made the commit, and some date-and-time stamps. This also includes a list of previous commit hash IDs, usually with exactly one entry in the list.

To keep the answer short, we won’t go into any more detail here except to say this: the files in the Git objects database are quite useless to anything but Git itself. In order for you to get any actual work done, you must have Git extract a commit. To do that, you use git switch or the older git checkout command to check out one specific commit (usually the tip commit of a branch; the word branch is badly abused in Git and has multiple meanings, but with some practice you’ll soon be flinging that word around as carelessly and automatically as everyone else).

Anyway, when you check out a branch, Git will:

This gives you a work area—which Git calls your working tree or work-tree—in which you have real, actual, ordinary computer files, not some special frozen-for-all-time Git-ized useless compressed things. But these files are not in Git. They came out of the commit you just checked out, but they are not in Git. In other words, when you work in a Git repository, you work on files that are not in Git at all. That’s why it’s important to commit often: only the committed files go into Git, and it can only get you back stuff you commit. Everything else is not in Git and Git can’t help you with it.

Review

Git stores commits and other Git objects in one of its two main databases. These have big ugly random-looking (but not actually random) hash IDs.

Git stores names, like branch names, in the other of its two main databases. These let Git find the hash IDs so that you can extract commits.

When you check out or switch to some branch name, you’re really checking out one particular commit: the tip commit of that branch. This gets you ordinary files to work on. Those files aren’t in Git.

When you use git add and git commit to make a new commit, Git makes the new commit, saving the files (and your name etc) within the database. The database mainly only ever gets added to, so once saved in a commit, you can almost always get all of this stuff back later. (The weasel wording here is because there are several ways to «lose» a commit, though it’s deliberately hard to do except by nuking the entire repository, or losing the computer or its storage—and those are things Git can’t help you with afterwards!)

Creating a new repository, and where the working tree is

When you run git init and it creates a new repository, it tells you this:

If you already have a repository, git init does nothing (well, almost nothing) and says instead:

What git clone really means, though, is:

In other words, this git clone step copies their commit objects database. A later git fetch hooks up with them again, and gets new commits, but doesn’t bother re-copying existing commits. All commits are frozen for all time, and their hash IDs are unique to those particular commits—no other commit anywhere, in any Git repository, is allowed to use that ID ever again—so just checking the IDs suffices, and your git fetch will efficiently add their new commits to your repository, without affecting any new commits you made, which have their own unique IDs.

(Now you know why the IDs are so big and ugly. They have to be, or your software might accidentally re-use an ID.)

Note that git clone does not copy their names database. Instead, they list out their names, and our Git software modifies those names:

(See what I mean about Git beating the word branch to death? What exactly do we mean by «branch»?)

What this does is have our Git software call up their Git software—just like for git fetch —but turn the direction around. This time, instead of getting new commits they have that we lack, we’ll send them our new commits that we have that they lack. So our Git will check their main or develop or whatever and see that we made one or two new commits, and will send over our new commits.

Here, again, push and fetch differ. Having sent over our new commits, our Git software now asks them, politely, if they would please set their branch of the same name to hold the new commit hash ID. They will agree if and only if this merely adds new commits to their repository. We won’t go into all the details here, but if you’re working with other people, on a shared hosted repository, and multiple people git push to the same name on that shared hosted repository, sometimes your git push would want to drop their commits. In that case, their Git will say no, I won’t do that, if I took your commits I’d have to drop Fred’s and Susan’s or whatever.

If your repositories are all private (not shared like this), this sort of thing is pretty rare. You may still encounter it, depending on how you use Git! But it won’t happen unless you make it happen yourself. So, again, we won’t go into any of the details.

Review of part 2

Fetch is the opposite of push, but they’re not true opposites: «fetch» can fetch all branches at once and is always safe because of remote-tracking names, but «push» pushes one branch at a time and doesn’t have anything like remote-tracking names.

Practice

Always start using Git with a practice repository that you don’t care about too much. 😀 You will stumble into oddities. You will sometimes want to just destroy the practice repository and start over.

git: обновления были отклонены, потому что удаленный содержит работу, которую вы не имеете локально

Я работаю над командой с несколькими разработчиками, использующими git на BitBucket. Мы все работаем над dev ветка, не толкая к master до релиза.

один из разработчиков совершил неправильный код, который случайно переписал мой собственный, и теперь я пытаюсь вернуть правильный код в репо. Я читал об этой ошибке в течение нескольких дней, я больше не могу нажать на репо, потому что я получаю следующую ошибку:

это действительно расстраивает, я действительно хочу помочь своей команде и внести свой вклад, но я не могу из-за этой ошибки. Делает кто-нибудь знает, как решить эту проблему? Я бы очень признателен за любую помощь.

это команды, которые я запускаю для фиксации, если это кому-то помогает:

Я бы подумал, что если бы я сохранил этот порядок, я не получил бы конфликтов слияния. Наверное, я ошибся. Еще раз спасибо

обновление: Я должен добавить, что я искал несколько часов в Google и stackoverflow и следовал различным инструкциям, но я все еще не могу push до dev отделение.

7 ответов

git pull master:dev получает remote/master филиала и объединить его в свой local/dev филиала.

git pull dev получает remote/dev ветвь, и объединить его в текущую ветвь.

используйте эту команду в терминал

как мы не приняли обновленный пульт дистанционного управления в нашей локальной среде. Так что возьмите тянуть сначала от remote

я исправил это, я не совсем уверен, что я сделал. Я попытался просто толкать и тянуть, используя:

git pull dev вместо git pull master:dev

надеюсь, это поможет кому-то, если у них такая же проблема.

У меня была эта ошибка, и это было потому, что на сервере было обновление, но SourceTree не показывал никаких доступных обновлений (возможно, потому, что я был в автономном режиме, когда он последний раз проверял). Поэтому я сделал обновление в дереве источника, и теперь он показывает 2 элемента для нажатия вместо 1 элемента.

поэтому обязательно нажмите клавишу обновить или тянуть если вы получите эту ошибку, а затем повторите попытку.

Примечание: Если вы случайно застряли в Редакторе vim после вытягивания репозитория, не волнуйтесь, просто закройте редактор vim и попробуйте нажать:)

вам нужно ввести:

Issue pushing new code in Github

I created a new repository on Github which has only Readme.md file now.

I have a newly created RoR project which I wanted to push to this repository. Following are the commands I gave in my Terminal to execute this along with the error I am getting.

After which I entered my username and password

This is my first time pushing my code to a Github repository and I’m lost with the errors. I searched few other questions that are asked here, but none of them had issues first time.

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

14 Answers 14

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

If this is your first push, then you might not care about the history on the remote. You could then do a «force push» to skip checks that git does to prevent you from overwriting any existing, or differing, work on remote. Use with extreme care!

just change the

change it like this!

Your local repository doesn’t know about this commit yet. Hence:

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

You may want to find to follow this advice:

You may want to first merge the remote changes (e.g., ‘ git pull ‘) before pushing again.

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

⚡️ EASY: All you need is a forced push. Because you might have created readme.md file on Github and you haven’t pulled it yet.

And here’s a GIF.

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

⚠️ BEWARE: Using force can change the history for other folks on the same project. Basically, if you don’t care about a file being deleted for everyone, just go ahead. Especially if you’re the only dev on the project.

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

Issue a forced push with the command:

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

This is happen when you try to push initially.Because in your GitHub repo have readMe.md or any other new thing which is not in your local repo. First you have to merge unrelated history of your github repo.To do that

then you can get the other files from repo(readMe.md or any)using this

Now you successfully push your all the changes into Github repo.I’m not expert in git but every time these step work for me.

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

Considering if you haven’t committed your changes in a while, maybe doing this will work for you.

That worked for me, hopefully it does for you too.

As local directory and git remote directory’s files conflicted.

Solution :

After committing all files to staging follow below steps.

Fetch the files from the remote repository as its conflict with the local working directory.

Commit the changes again.

After committed merge files with both directory you can use

This will fix the issue. Thanks.

if you use the git for mac in GUI you can chose Respository->Pull or the «comm+shift+p» to «git pull» first, then publish the source.

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

I had a similar problem. I resolved it like this (i’m not an git expert so i don’t know if it is a right solution, but it worked for me):

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

I struggled with this error for more than an hour! Below is what helped me resolve it. All this while my working directory was the repo i had cloned on my system.

If you are doing adding files to your existing repository** 1. I pulled everything which I had added to my repository to my GitHub folder:

Output was- some readme file file1 file2

eg. some readme file file1 file2 newfile1 newfile2

git add «newfile1» «newfile2»

[optional] git status this will assure you if the files you want to add are staged properly or not output was

And all my new files along with the older ones were seen in my repo.

I have some projects I would like to upload on my bitbucket private profile. I performed the following steps but I get an error.

Convert my project to git with: git init

I created a bitbucket repository and version control system is GIT.

I then type this (of course with real account name and reponame and repo owner):

I did all of this and my terminal gives me this error:

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 works for me.

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

Your master branch has some code that you don’t locally have, and to prevent you from conflicts, it doesn’t let you to push further changes, before you have them locally. To resolve this, pull all the changes to your local repository (your project):

After that, you will have all the code that is available on your master branch.

NOTE: Be careful, pulling the code from remote branch might mess up all the changes locally. Make sure to save those changes somewhere, or create another branch locally where you will pull your origin master branch, so it doesn’t mess up your changes.

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

Your issue is that you have different things between your local repository and your git repository (probably a readme file that you created automatically), so you have two options:

git push rejected

I give up! Whenever I try to push I get a stupid:

Our team has a new git setup. Instead of making private branches I now Forked our main repository (on github) to create my own copy.

At some point what I did was:

So here is my current setup::

where userX is my private repository.

So I go and make some changes to my upstreammaster branch, and the PULL from «upstream master». Everything merges and stuff:

but then when I try to do:

Any help would be greately appreciated! If you need clarification please ask, I will reply!

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

8 Answers 8

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

When doing a push, try specifying the refspec for the upstream master:

Edit/Clarification

Assuming your upstreammaster branch is ready to push then you could do this:

Pull in any changes from the upstream.

$ git pull upstream master

Switch to my local master branch

$ git checkout master

Merge changes in from upstreammaster

$ git merge upstreammaster

Push my changes up

$ git push upstream

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

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

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