im currently learning how to use the git&github, the first time i pushed items there it worked perfectly fine, but now when im trying to update it it keeps failing... any suggestions? The window I put all my commands on
-
1Please share any relevant code by editing your Question - [instead of a screenshot](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question). Fewer people are likely to reproduce your issue without having your code in a copyable form. – tjheslin1 Oct 31 '21 at 11:52
-
1You’ve got a bunch of issues here. I don’t see how it worked before since git seems to think the local repo and the origin remote are unrelated – evolutionxbox Oct 31 '21 at 11:53
-
1The key line is the output of running `git init`: `reinitialized exiting Git repository`. You already had a git repo here which already has a remote `origin`. You _could_ force push on top of the previous changes, however I would recommend running `git init` in a new, empty, directory; assuming you want to start from scratch. – tjheslin1 Oct 31 '21 at 11:54
-
@tjheslin1 that may also explain why the commit is unrelated to the remote. – evolutionxbox Oct 31 '21 at 11:57
-
Git is showing you lots of error messages and warnings. Reading instead of ignoring them helps a lot – knittl Oct 31 '21 at 12:34
3 Answers
The problem is that someone updated the remote repo meanwhile and you haven't updated your local repo accordingly. To solve it please run the following commands:
git pull --allow-unrelated-histories
git push origin master
EDIT: It isn't working because the local and remote repos have unrelated histories. To solve it you can run the edited commands. :)
"git merge" used to allow merging two branches that have no common base by default, which led to a brand new history of an existing project created and then get pulled by an unsuspecting maintainer, which allowed an unnecessary parallel history merged into the existing project. The command has been taught not to allow this by default, with an escape hatch
--allow-unrelated-histories
option to be used in a rare event that merges histories of two projects that started their lives independently.
Source: This stackoverflow answer.

- 169
- 9
-
-
1Whilst correct, this may cause more issues. Especially since the user is a learner of git – evolutionxbox Oct 31 '21 at 11:58
-
I faced a similar issue and this solved it and from then on I have had no issues. I too am a learner of Git. – Jithin Oct 31 '21 at 12:04
-
It may do, but it would be better to understand why this happened and then learn to prevent it in future. – evolutionxbox Oct 31 '21 at 12:05
-
@Arik Tatievski please try this out and please inform if it doesn't work. So that I can improve :) – Jithin Oct 31 '21 at 12:06
-
-
It will work. It’s just that this doesn’t prevent the OP from doing this again, nor does it explain why it happened in the first place. – evolutionxbox Oct 31 '21 at 12:09
-
The error "The tip of your current branch is behind its remote counterpart" means that there have been some changes on the remote branch that you don’t have locally.
Git
is implying you to import the new changes from the remote branch (using pull
) and merge it with to your code base. after that you will be able to push it to the remote branch via push
.
You can use also use this command to force changes to the server with the local repository. this will replace your remote code with your local repo code.
git push -f origin master
The -f
flag (force) let's you override the remote branch code with your local repo code.

- 14,906
- 5
- 47
- 53
It also says that
nothing has been added to commit but untracked files present
Maybe it is not finding the dir src
that you have used in the command:
git add src
If you want to add everything you've modified in your repository you can use:
git add -A
If you are sure everything is correct though you can use:
git push origin master --force

- 1,362
- 3
- 12
- 34