0

I have a project in my windows laptop and I'm using MS Visual Studio Code.

I installed git on windows, addded a repository and commited my code.

Created a repository on GitHUB and added to my local with this command:

git remote add Codeigniter-starter-kit https://github.com/rostamiani/Codeigniter-starter-kit

Now when I try to publish branc, this error comes up:

git push -u Codeigniter-starter-kit master To https://github.com/rostamiani/Codeigniter-starter-kit ! [rejected]
master -> master (fetch first) error: failed to push some refs to 'https://github.com/rostamiani/Codeigniter-starter-kit' 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.

There is just a readme in the remote. I tried to pull it and this time this is the error:

git pull --tags git show :application/controllers/Test.php Auto packing the repository in background for optimum performance. See "git help gc" for manual housekeeping. warning: There are too many unreachable loose objects; run 'git prune' to remove them. There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details.

git pull

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=Codeigniter-starter-kit/ master

git show :application/controllers/Test.php git status -z -u git symbolic-ref --short HEAD git rev-parse master git rev-parse --symbolic-full-name master@{u} fatal: no upstream configured for branch 'master' git for-each-ref --format %(refname) %(objectname) --sort -committerdate git remote --verbose What's wrong?

rostamiani
  • 2,859
  • 7
  • 38
  • 74
  • Possible duplicate of [Git refusing to merge unrelated histories on rebase](https://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories-on-rebase) – Code-Apprentice Jul 27 '18 at 05:40

2 Answers2

4

You can do one of two things:

  1. Explicitly pull the master branch with git pull origin master instead of just git pull.

  2. Force push your local code with git push -f origin master. This will overwrite the master branch on your GitHub repo and you will lose the README file.

To learn more about the basics of Git, I suggest reading the first three chapters of Pro Git. This will give you the tools you need in order to use git successfully and to recover from problems such as this.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • Force push did the job. But why I couldn't pull? (fatal: refusing to merge unrelated histories) – rostamiani Jul 27 '18 at 01:27
  • 1
    @rostamiani Probably because the two branches start with an orphaned commit which does not have any parent. Neither branch shares any commits in common and so git refuses to merge them. – Code-Apprentice Jul 27 '18 at 01:34
0

You need to run git pull origin master first as the file tracking on your local repo is different with the remote repo

Ardian
  • 1
  • 1