Problem when pushing on Github

Asked

Viewed 8,005 times

1

Oops, I’m trying to send my files to a repository on github but it’s going wrong. I did it this way:

git init
git add .
git commit -m "xxx"
git remote add origin https://github.com/rodriguesJeff/classes_dbv/
git push origin master

But you’re making the following mistake: inserir a descrição da imagem aqui

Then I give the git pull and give it:

 * branch            master     -> FETCH_HEAD

Help there pls

3 answers

3

This occurs when your local version (on your machine) is "delayed" compared to your remote version (in your case, which is on Github). Imagine the following scenario:

  1. You create a file teste.html with the content below and does the commit and push to save to Github
<html>
<head>
    <title>Helo World</title>
</head>
<body>
    <h1>Helo World</h1>
</body>
</html>
  1. Your coworker who has nothing to do (or even yourself on another machine) looks at this file and changes the texts, translating into Portuguese. Again saved on Github

  2. The other day you want to do an animation test with the title on the page, you commit but when trying to save on Github, do this mistake

The solution is to do the pull first to sync the location to the remote and then save, but be careful, depending on the situation it may be that some conflict change, if you are using a good IDE it will alert you

In some situations you may want to write the local code on top of the remote, I do it a lot, sometimes I forget to commit some file and go back to the previous commit, recommit (this time with the missing file) and Fasso push using the option --force

1


Just run the following commands and then push again

git fetch
git reset --hard origin/master

-1

And for whoever’s getting:

fatal: The current branch main has no upstream branch when push

execute in the folder of your project:

git push --set-upstream origin master

Browser other questions tagged

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