I was working on a project made some changes in my code (in Itellij IDE) and by mistake I did below two steps in my terminal and I saw some changes went into the main respository (not my changes or anything I had worked previously). Does anyone know why it did it ?
Note: Changes that were pushed were not my code.
git push (rather than "git add" and "git commit") from my terminal
I could not understand why git did that and thought of asking a question here to understand.
The question was asked to know possible cause without influencing my view on the answer.
It is difficult to say precisely what happened since you did not tell us the state of your local branch at the time you did the accidental git pull
followed by git push
. Assuming you started off with no local commits which did not already appear on the remote tracking branch, then I would have expected git push
to fail by saying that the remote is already up to date. The sign for this would be if you had run git status
right before the accidental git pull
and Git told you that your branch was 0 commits ahead of the remote.
For the second step, you did a git push
. Assuming this went through, then I would interpret it to mean that you did in fact have some local commits which were not pushed yet. So, all that happened is that some of your previous local work was pushed to the repository, perhaps prematurely. Assuming those commits were made in good faith, you may have nothing to worry about. If not, then you could always revert one or more of those commits by using git revert
.