This situation I work alone with iOS in Xcode (maybe it matters)

And I do commits in the process of work and suddenly I see that the remote branch was separated for some reason (probably I did something wrong, but still the strange behavior of the branch, provided that I am alone in this repository).

It looks like this now.

enter image description here

when I write git push then in output it says that you need to do git pull first (as it happened, what I need to do is not clear git pull, I work in one branch ...).

Ok, I do git pull I get a conflict in the Main.storyboar file, such conflicts are very hard to fix (at least for me a newbie in iOS), I can't even open this file.

It looks like this

enter image description here

So now the question is, can I somehow rewrite the remote master branch?

I have a normal local master branch and I just want to upload it to the remote repository on top of the master that’s there now and don’t do any merge and pull, just write it on top as the main one

Can this be so?)


This is what happens if you run the git push --force master from the @KoVadim response

 Admins-MacBook-Pro:Fitzz admin$ git push --force master fatal: 'master' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 

With such a command git push --force origin master I get this output

 Admins-MacBook-Pro:Fitzz admin$ git push --force origin master Counting objects: 39, done. Delta compression using up to 8 threads. Compressing objects: 100% (39/39), done. Writing objects: 100% (39/39), 11.10 KiB | 0 bytes/s, done. Total 39 (delta 23), reused 0 (delta 0) remote: GitLab: You are not allowed to force push code to a protected branch on this project. To https://gitlab.com/alekseytimoshchenko/FitzzIOS.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'https://gitlab.com/alekseytimoshchenko/FitzzIOS.git' Admins-MacBook-Pro:Fitzz admin$ 

edit

 Admins-MacBook-Pro:Fitzz admin$ git fetch Admins-MacBook-Pro:Fitzz admin$ git checkout master Already on 'master' Your branch and 'origin/master' have diverged, and have 7 and 1 different commits each, respectively. (use "git pull" to merge the remote branch into yours) Admins-MacBook-Pro:Fitzz admin$ git merge Auto-merging Fitzz/Main.storyboard CONFLICT (content): Merge conflict in Fitzz/Main.storyboard Auto-merging Fitzz/Info.plist CONFLICT (content): Merge conflict in Fitzz/Info.plist Auto-merging Fitzz/CameraViewController.swift CONFLICT (add/add): Merge conflict in Fitzz/CameraViewController.swift Auto-merging Fitzz.xcodeproj/project.pbxproj CONFLICT (content): Merge conflict in Fitzz.xcodeproj/project.pbxproj Automatic merge failed; fix conflicts and then commit the result. Admins-MacBook-Pro:Fitzz admin$ git checkout --ours -- Fitzz.xcodeproj/project.pbxproj Admins-MacBook-Pro:Fitzz admin$ git checkout --ours -- Fitzz/CameraViewController.swift Admins-MacBook-Pro:Fitzz admin$ git checkout --ours -- Fitzz/Info.plist Admins-MacBook-Pro:Fitzz admin$ git checkout --ours -- Fitzz/Main.storyboard Admins-MacBook-Pro:Fitzz admin$ git status On branch master Your branch and 'origin/master' have diverged, and have 7 and 1 different commits each, respectively. (use "git pull" to merge the remote branch into yours) You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge) Unmerged paths: (use "git add <file>..." to mark resolution) both modified: Fitzz.xcodeproj/project.pbxproj both added: Fitzz/CameraViewController.swift both modified: Fitzz/Info.plist both modified: Fitzz/Main.storyboard no changes added to commit (use "git add" and/or "git commit -a") 

    1 answer 1

    In general, you need a forced push. git push --force origin master . But this is a very dangerous command and it mills the current branch on the remote repository. If you work on your own - rather nothing will be wrong. But if you work in a team, you need to think ten times and still not do it.

    Judging by the picture - there is now in the process of merge (but I'm not sure - guards to utilities of confidence zero). But if you swear that now merge - you can cancel git merge --abort .

    If this strategy does not work, you can still try to do it "correctly."

    first we will pull up the deleted changes (well, not enough)

     git fetch 

    switch to master

     git checkout master 

    handles

     git merge 

    here we will have conflicts. They need to be solved. To start doing

     git status 

    and look at the conflict files. Since you want to forget about the remote master, we will be "in our direction." For each conflict file do this

     git checkout --ours -- <имяфайла> 

    with this team we tell the gita that we want to resolve the conflict, saying that our version of the file is correct.

    and do not forget to tell the gita that we solved the conflict

     git add <имяфайла> 

    and look at git status again - there shouldn't be files with "both modified". Now you need to compile in the development environment and check that everything works. If everything suits - commit and push

     git commit -m "merge master" git push 
    • But in my situation, this is what I need as I understand it? I tried this command but failed, added to the question - Aleksey Timoshchenko
    • there was a word lost. - KoVadim
    • it still didn't work out (Added to question. - Aleksey Timoshchenko
    • It looks like you have a "protection against a fool" on the hitlab (and this is good). How to reconfigure the guitar club - I will not say. - KoVadim
    • hmm ... ok, maybe there is still an idea what to do in this situation? - Aleksey Timoshchenko