-2

I'm trying to uploud my local project for the first time, when I do the $git push command the following error is returned:

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

After applying the tip the error is returned:

Warning: Permanently added the RSA host key for IP address '---------------' to the list of known hosts.
To github.com:LuisMatheus-dev/Gama-Academy.git
  ! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com: LuisMatheus-dev / Gama-Academy.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.

How should I proceed ?

luis matheus
  • 197
  • 1
  • 8
  • 1
    Does your network work? What does `git status` and `git log` say? What does the commit history on github look like. Why are you pushing master to master? Surely you should be pushing to origin/master? What command did you use for `git push`? In general please include lots of detail. Rarely can you provide too much detail – PiRocks Apr 25 '20 at 19:53
  • 2
    Also what have you tried? Have you googled your error message first? – PiRocks Apr 25 '20 at 19:54
  • Does this answer your question? [How to resolve git error: "Updates were rejected because the tip of your current branch is behind"](https://stackoverflow.com/questions/22532943/how-to-resolve-git-error-updates-were-rejected-because-the-tip-of-your-current) – phd Apr 25 '20 at 20:17
  • https://stackoverflow.com/search?q=%5Bgit%5D+Updates+were+rejected+because+the+tip+of+your+current+branch+is+behind – phd Apr 25 '20 at 20:17
  • I edited the question for more details – luis matheus Apr 25 '20 at 20:19

1 Answers1

1

The remote master contains commits that your local master does not. Maybe this answer helps.

Michael Kreutz
  • 1,216
  • 6
  • 9
  • I had seen this topic but I was in doubt as to *git fetch*. Would it overwrite changes to the local repository? Because there is nothing in the github repository – luis matheus Apr 25 '20 at 20:25
  • If you really want to push to remote master then you can stash your local changes first with `git stash`, then execute `git pull` to not override your changes and the execute `git stash pop` to unstash your changes. `git fetch` does not override anything it fetches the most recent information from your remote. – Michael Kreutz Apr 26 '20 at 07:50
  • 1) Run **$git stash**: `Saved working directory and index state WIP on master: 64da888 Banner image` 2) **$git pull origin master**: `From github.com:LuisMatheus-dev/Gama-Academy * branch master -> FETCH_HEAD fatal: refusing to merge unrelated histories` – luis matheus Apr 26 '20 at 14:46
  • It seems like your local master and remote master are not really compatibel anymore.. Try the following. First, leave your changes stashed, then create a new branch `git checkout -b master-backup`, then delete your local master `git branch -D master`, then checkout the remote master `git checkout master`. Finally you can merge your master-backup to master and push it again. – Michael Kreutz Apr 26 '20 at 14:57
  • Okay, but when I went to do the **$ git merge master-backup** it returns the error: `fatal: refusing to merge unrelated histories` – luis matheus Apr 26 '20 at 15:14
  • As suggested in https://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories-on-rebase `git merge --allow-unrelated-histories` should work... – Michael Kreutz Apr 26 '20 at 15:46
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/212559/discussion-between-luis-matheus-and-michael-kreutz). – luis matheus Apr 26 '20 at 16:44