git hub ! [Rejected] - I can’t find the files for github

Asked

Viewed 374 times

0

I’m trying to send my code to the Github, but I can’t. Follow a tutorial, so I’m in the right folder and stuff. I made a git add all, gave commit in everything, the git status appears in the "print" for you to take a look, but then the error occurs.

A few attempts before he also asked for my login and password Github, but now not even that.

inserir a descrição da imagem aqui

I don’t know how to fix

  • I have already done the right direction too, in the . git folder, the config file is sending to the link of my properly created directory in Github

2 answers

2

The git is already showing you the problem and the solution:

Updates were rejected because the tip of your current branch is behind

That is, you have the outdated branch because someone has already moved something up to the "remote" area and you didn’t bring these changes. To resolve, simply update your branch:

git pull

When you do this, you may need to do some "merge" of files, in this situation the git will alert of conflicts. In that case you just need to resolve them, and then "commit" the changes normally.

  • I sent a git pull, what should I do now? try to push again?

  • I still can’t make it work.

  • @Giovanemachado after doing the git pull, what result? Did you get an error message? If it all happened "ok", you did the git push origin <branch> again? Appeared any error message?

  • There is no tracking information for the Current branch Please specify which branch you want to merge with. See git-pull(1) for Details. git pull <remote> <branch> If you Wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/<branch> master

  • The git pull returns this, and then I tried again to git push origin master and the initial error repeats

  • @Giovanemachado use git pull origin master and if it doesn’t work, use git branch --set-upstream-to=origin/master master. That way it will download the changes from master branch

  • The first returned: From https://github.com/GiovaneMachado/my-first-blog * branch master -> FETCH_HEAD fatal: refusing to merge histories

  • @Giovanemachado Try to do git pull origin master --allow-unrelated-histories or git fetch origin. If you created the repositories (local and remote) independently, instead of cloning the remote repository, this is the reason for the error.

  • The first one worked! I then did a git push and it’s all in my Git Hub. No big words, thanks. Can you explain how you solved it? If you can do it as a better answer, but anyway, thank you very much!

  • I couldn’t even answer, but it would complement what @Valdeirpsr actually said. That’s necessary because you didn’t clone the repository. When you create one from scratch you need to link it to the remote repository because locally it’s like the branch doesn’t exist. What the allow-unrelated-histories option does is merge the changes of two existing repositories to allow push.

Show 5 more comments

2


The error displayed happens basically in the following situation:

  • Changes are made to the remote repository and these changes are not applied to the local repository

In your case, the error message specifies the following:

Updates were rejected because the tip of the current branch is delayed compared to the remote repository. Integrate Remote Changes (Using git pull …) before "send" again.

However, if you have created the repositories independently, for example: you create the repository on Github and also creates a local repository with git init, the git can interpret that are two distinct projects and in such cases you will get the error below:

fatal: refusing to merge unrelated histories

By default, the git merge¹ refuses to merge stories that do not share a common ancestor. This is rare to happen, but if it does, you can use the parameter --allow-unrelated-histories.

This parameter can be used to replace this security by combining stories of two projects that started their lives independently, for example:

git pull origin master --allow-unrelated-histories

Attention! You should not use –allow-unrelated-histories in all cases, unless you know what an unrelated history is and you’re sure you do. Verification was introduced only to prevent disasters when people merge unrelated projects by mistake. ²

¹ The command git pull is - basically - the junction of commands git fetch + git merge.

Reference:
² https://stackoverflow.com/a/39783462/9101590
https://git-scm.com/docs/git-pull

Browser other questions tagged

You are not signed in. Login or sign up in order to post.