momodjib
momodjib

Reputation: 193

unable to push git commits after set up

I just installed git on my computer following all the informations on their website but I'm kind of stuck. After commiting my files, I run git push and I get:

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

So I run git push --set-upstream origin master, then I get: push message.

After that I figured I should do a pull first and push after, but I get another message: pull message.

I followed all the steps and finally got to a message saying:

branch 'master' set up to track remote branch 'master' from 'origin'.

After this last one I tried another pull and got:

fatal: refusing to merge unrelated histories.

I don't think I need to say that I'm new to git, it's probably obvious haha, can someone help please ?

Upvotes: 0

Views: 296

Answers (1)

Reece Trolley
Reece Trolley

Reputation: 61

It looks like you went into GitHub to create the repo, made some changes, then went onto to your computer, initialised the repository and made some changes.

Since the changes from GitHub were never in your local commit history, the two branches have no similarities.

To fix this, if you are absolutely sure the code you have on your computer is what you want to upload you can use

git push --force

To manually overwrite your git history on GitHub. Be aware this will remove any changes you made anywhere else, but should give you the clean slate to carry on.

In future you should either set up on GitHub then clone the repository to make changes; or set up on your machine then push to an empty repository. This keeps the commit histories in check.

If you want to keep the changes from GitHub and discard your local changes, you can instead use

git reset --hard origin/master

Which will remove all local changes - so again, be careful.

Upvotes: 1

Related Questions