GIT PUSH --SET-UPSTREAM ORIGIN MASTER ERROR

Asked

Viewed 8,960 times

0

I’m trying to make a git push, but this error always arises:

$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master


dell latitude@DESKTOP-KU6NT53 MINGW64 ~/Downloads/hellospringboot (master)
$ git push --set-upstream origin master
To https://github.com/LealVinicius/arqdesint.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/LealVinicius/arqdesint.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.
  • 2

    Updates were rejected because the remote contains work that you do not have locally What the above error is saying is that you don’t have in your local repository the latest changes that were received in your remote repository on Github. Generally, just run git pull origin master before doing the push again.

1 answer

0

The warning that the command git push is sending signals that your tree is out of sync with the master branch Github. In this case you have two options:

  1. ignore the differences and overwrite the branch master who is at Github doing a push forced;
  2. make a merge of the two branches (your local master and that of Github) and make again a git push.

The first option is the simplest and riskiest. It will ignore commits from master branch of Github and will write it with your branch local. For this it is sufficient to add the argument --force:

$ git push --set-upstream --force origin master

In case the server keeps refusing yours push, check if the option to refuse Forced pushes is enabled in the configuration of your Github repository and disables it.

The second option is a little more complicated but is safer. It should be executed in a few steps:

  1. do checkout of master branch local: git checkout master
  2. certify that you have the exact copy of master branch Github with the command git fetch origin;
  3. merge your master branch with the branch github: git merge origin/master;
  4. if there are issues such as conflicts, for example, resolve them and commit (git mergetool?);
  5. finally do the push: git push --set-upstream origin master

Ah, you can join steps 2 and 3 in just one if you use the command pull: git pull origin

Browser other questions tagged

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