please help me with this small error. I am trying to push 3 files from my local repo to a remote and the remote repo has a .gitignore file. I have tried a pull as the error said but I got the same error again. I don't want to do a force push. Before doing this, I have created an empty repo on GitHub and I have pushed all the 3 files successfully. Later I deleted that repo and created another repo with .gitignore which has the same name as the old one. It would be great if you explain what is happening. I have tried pulling the remote repo so that my local repo would be updated but that didn't work.
-
Just because your repo has the same name doesn't mean it is the same repo. Did you set the remote of the new repository to be the one on GitHub, or is the new repository a clone of the remote? If you just created a new repository from scratch and added a commit, then it is obviously different from the repository on GitHub, since they do not share a common commit. – Andrew Fan Jun 05 '18 at 20:00
-
Yes, I did that. – Swaroop Meher Jun 05 '18 at 20:05
-
Don't provide information as image which can be text. – Kalle Richter Jun 05 '18 at 20:17
3 Answers
Every git repository contains a .git hidden directory that contains the details of the repository. When you run git init
, you create a new git repository, including a new .git directory. The first commit you make in this directory is the initial commit - the first set of changes logged in the repository.
If you create another git repository using git init
and make a commit in it, even if it has the same folder name (which is actually irrelevant) and you committed the exact same file, the initial commit of this new repository will be different from the initial commit of the original repository.
These two repositories may have the same name and the same files, but they are not the same repository and they have no shared history.
Now, in your case, you pushed the original repository to GitHub, then deleted your local copy of the repository. If you created another repository locally, even though it may have the same files, it does not have the same commit history as the remote on GitHub and therefore cannot pull from or push to the remote.
I recommend cloning the remote repository from GitHub to your local machine and using that repository for future pulls and pushes.

- 1,313
- 5
- 17
- 29
-
If you deleted the repository from GitHub (i.e. scrolled down, typed in the repo name, hit the red button), then the remote no longer exists, so pushing and pulling will obviously not work anymore. Assuming you created a new repository on GitHub separately from your local copy, then this answer should still apply to an extent, as they are two separate repositories with no shared history. – Andrew Fan Jun 05 '18 at 20:17
Maybe your branch got detached if other people are working on the repo too. Try a rebase, then commit/push back.

- 104
- 10
You can refer to this. You can use --allow-unrelated-histories to force the merge to happen.

- 183
- 1
- 2
- 13