1

I've a problem with GIT for push into an empty repository with this error when I do git push --set-upstream origin master.

On Windows I type in project's folder:

git init
git remote add origin https://almatoolbox.visualstudio.com/xxxxxxx/_git/TS_smartroad-tests
git add .
git commit

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

then I type:

git push --set-upstream origin master

but I have this error:

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://almatoolbox.visualstudio.com/ANAS/_git/TS_smartroad-tests'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I want deploy my project folder into branch master and develop. Is it possible? If i do git pull origin master i have this error:

git pull origin master
From https://almatoolbox.visualstudio.com/ANAS/_git/TS_smartroad-tests
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

git remote -vv
origin  https://almatoolbox.visualstudio.com/xxxxxxx/_git/TS_smartroad-tests (fetch)
origin  https://almatoolbox.visualstudio.com/xxxxxxx/_git/TS_smartroad-tests (push)

and my branches are:

git branch -vv
develop 87d2624 [origin/develop] Deleted pom.xml
* master  824e4a7 ok
Catanzaro
  • 1,312
  • 2
  • 13
  • 24
  • Did you read the guidance in the git error, or any of the (very many) Qs, As, blog posts and articles about that issue? – jonrsharpe Apr 16 '20 at 14:48
  • Read the `hint` in the error message – EncryptedWatermelon Apr 16 '20 at 14:50
  • remote is EMPTY!!! if i do git pull: I have error: git pull origin master From https://almatoolbox.visualstudio.com/xxxxxxxx/_git/TS_smartroad-tests * branch master -> FETCH_HEAD fatal: refusing to merge unrelated histories – Catanzaro Apr 16 '20 at 14:52
  • 1
    You remote is certainly not empty. You've created a repository and initialized it with `README` or `.gitignore`. To see the diff: `git fetch origin && git diff origin/master HEAD` – phd Apr 16 '20 at 17:42

1 Answers1

0

Your remote is NOT empty. That's exactly what the error messages are telling you.

Proof:

  1. run git fetch --all
  2. then git log --graph --oneline --all

You will see origin/master, a reference to the existing master branch on the remote. It and any other remote branches will be colored red depending on how git is configured.

⚠️ Warning: I hesitate to give you the following information, because you show signs of not understanding git, and run the risk making an irrecoverable risk. Proceed at your own risk.

If you are absolutely sure that you don't want any of the existing commits in origin/master, such as if @phd is correct that it is just the default README created by GitHub1, you can:

  1. git checkout master (to make sure you are on master locally)
  2. git push --force: this will overwrite master on your remote.

1When you create a fresh GitHub repo, can tell it not to create an initial commit with a default README.md

Inigo
  • 12,186
  • 5
  • 41
  • 70