I can not figure out the mechanics of the action, why it does not work ... There are files in the local git repository. There is a project in GitLab (already contains files, but they differ from files from the local repository). Created a remote repository. You must send files from local to remote. When trying to push, an error is generated:

 " ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'ссылка на проект в GitLab'е' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (eg hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details." 

I pull - git produces the following error:

 branch master -> FETCH_HEAD fatal: refusing to merge unrelated histories 
  • Warning: if you make a pull from a remote repository, it will replace your local files (if successful, of course) - Evgeny Shalaev
  • I did not understand the essential details from the question. Was the repository originally locally, then they created a repository in the gitlab and are trying to push everything from a local computer there? Or was there a gitlab project, it was locally cloned, it worked, and then they tried to push it, but it turned out that the repository went forward N commits? - AK
  • @ Evgeny Shalaev, it turns out that if I pull, then the files from the Gitlab server will be copied to the local repository, and the files contained in it at that time will be deleted? - Ekaterina Stebakova
  • @EkaterinaStebakova are not deleted, but overwritten, so that there are both on the server and locally, new files will remain) and to be the opposite, you need to push) - Evgeny Shalaev
  • @ Evgeny Shalaev The fact is that the files in the local repository and remote are different. The task is to add files from the local server to the server. Push does not work ... When I uploaded data to an empty GitLab project, everything was OK - Ekaterina Stebakova

3 answers 3

Thank you all for your help. The question was resolved as follows (maybe someone will come in handy): 1) deleted all previously created repositories, 2) created an empty local repository (only those files I need to add to the server were left in the repository folder), 3) then created remote, 4) done pull, 5) added files to local repository (git add, git commit), 5) did push to server

    Git writes: refusing to merge unrelated histories (refusal to merge unrelated stories). Those. he does not see the repository connections, so he can neither accept an external repository, nor send data to it.

    The local repository does not seem to have been created by compiling the remote. In this case, you'd better create a new repository via git clone ... Or, if you are sure that the repository was created correctly, check the configuration of the remote repository in git remote

    • The settings indicate that for pull - master merge with remote master for push - master pushes to master (local out of date) - Ekaterina Stebakova
    • no-no-no, if we come to the settings, then we need to check what is there. Can you verify that the paths are correct for remote repo? the git remote show origin command (if you have a remote repo called origin ) - that guy

    If you first created a project in the folder and then on the githaba and want to upload your local project to the server, then in your case you had to do the following:

    '######################################

    Upload local repository to github:

    '######################################

     git init git add . git commit -m "First commit" 

    Add a local repository link to the github remote repository

     git remote add origin https://github.com/ut4utc/swift.git 

    Now you can push the remote repository

     git push origin master 

    Thereby sending your local master branch to the origin server (to the github repository). Now you can see the added files on github.