0

I have to branches with 2 developers and making merge:

 git checkout main Already on 'main' Your branch is ahead of 'origin/main' by 8 commits. (use "git push" to publish your local commits) 

Pushing changes to main branch I got error

localos:/path_project$ git push -u origin main Password for 'https://[email protected]': To https://github.com/client_name/project_name.git ! [rejected] main -> main (fetch first) error: failed to push some refs to 'https://[email protected]/client_name/project_name.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 hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

But I am last who pushed to main and I run git stash, so fixing errors I run:

localos:/path_project$ git stash apply CONFLICT (rename/delete): resources/views/adminside/project_product_brand/index.blade.php deleted in Stashed changes and renamed to resources/views/adminside/platform/index.blade.php in Updated upstream. Version Updated upstream of resources/views/adminside/platform/index.blade.php left in tree. CONFLICT (rename/delete): resources/views/adminside/project_product_brand/edit.blade.php deleted in Stashed changes and renamed to resources/views/adminside/platform/edit.blade.php in Updated upstream. Version Updated upstream of resources/views/adminside/platform/edit.blade.php left in tree. CONFLICT (rename/delete): resources/views/adminside/project_product_brand/create.blade.php deleted in Stashed changes and renamed to resources/views/adminside/platform/create.blade.php in Updated upstream. Version Updated upstream of resources/views/adminside/platform/create.blade.php left in tree. CONFLICT (modify/delete): public/js/app.js deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of public/js/app.js left in tree. CONFLICT (rename/delete): app/Http/Requests/ProjectProductBrandRequest.php deleted in Stashed changes and renamed to app/Http/Requests/PlatformRequest.php in Updated upstream. Version Updated upstream of app/Http/Requests/PlatformRequest.php left in tree. 

Not sure what have I to do with last errors ?

3
  • 2
    What does it say if you pull the latest changes? Commented Jul 26, 2021 at 12:09
  • 4
    The two commands you are discussing have very little relationship: "push" is concerned with synchronising a set of commits between two copies of the repository; "stash" is concerned with managing uncommitted changes within your copy. There are hundreds if not thousands of pages online explaining both "failed to push" errors and edit conflicts, and it's not clear what your specific question is. Commented Jul 26, 2021 at 12:10
  • 2
    Also, conflicts are not errors. Commented Jul 26, 2021 at 12:21

1 Answer 1

1

The command git push -u origin main failed because something in the remote is new compared to your local branch. That usually means somebody else pushed commits there, but it could also be the case that you changed your local history by for example amending a commit or doing an interactive rebase.

Note that you need to run git fetch if you want your local repository to "know" about any remote changes. The fact that you got the message Your branch is ahead of 'origin/main' by 8 commits. means that there's nothing new in the remote branch according to the last git fetch, but something new could appear after it. Since you got a rejection error when trying to push changes, you should run git fetch and git status, and it's very likely that you'll get a message like:

Your branch and 'origin/main' have diverged, and have X and X different commit(s) each, respectively.

In that scenario, you should update your local branch before pushing it, with git pull or git pull --rebase, solving any conflicts that the pull may cause, and then you would be ready for git push.

About git stash, it looks like applying your stashed changes generated some conflicts. It looks like an unrelated question, but I assume you tried several things to solve the same problem. I think it's important to explain that conflicts are not errors, but differences git doesn't know how to solve when merging 2 branches. Whenever you have a conflict when doing a pull, stash apply or other operations (rebase, merge, cherry-pick, etc), you can solve the conflicts manually by editing each conflicted file. Each conflict will be marked like this:

... <<<<<<< destination:xxxxxxxxxxxxxx ... // version in destination branch ======= ... // version in original branch >>>>>>> source:xxxxxxxx ... 

so you have both versions and can decide what the resulting version of those lines should be. Note that you have the commit hashes there and you can use git show xxx any time to make sure which commit is the one you're trying to apply. Once you solve all the conflicts in a file (leave the "correct" version and clean all conflicts marks), you can git add <file> to mark that file solved.

Once you solve all the conflicts in all files you can continue the operation you were doing. Some git operations have a --continue flag to continue after solving conflicts (git rebase --continue or git cherry-pick --continue), but if you're doing a "not so clean" operation, such as pulling without --rebase or applying a git stash, you will need to manually create the commit that solves the conflicts with git commit.

Finally, in case it helps you as you're trying different things and could potentially be creating a bit of a mess, remember that every commit you create is unique and you can always restore any version from the past even if you rebased, applied stashes, etc. With git reflog you can see all the versions you moved through. And many operations also have a --abort flag to abort them in case you can't solve the conflicts. And probably git reset and git reset --hard can help you too in order to reset your branch to a different version if you need to undo any mess.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.