-1

I had made some changes to my code and had updated my git to add these new changes to my repository but it is coming as followed.

On branch main
Your branch and 'origin/main' have diverged,
and have 2 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

nothing to commit, working tree clean

And my repository is not accepting the new changes that i have made in my code.

I tried to check for the new branch that git said that had been formed but nothing came up. And without a branch name i am not able to continue forward.

! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/ArjunKallatt/Projesctpython.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

This is what it showed when i tried to push the new commit and changes.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Nothing to do with Python or Linux specifically. Please don't randomly apply tags! – Ulrich Eckhardt Dec 12 '22 at 07:10
  • [Use the search function (preferably *before* asking).](https://stackoverflow.com/search?q=%5Bgit%5D+Updates+were+rejected+because+the+tip+of+your+current+branch+is+behind) – torek Dec 12 '22 at 08:30

2 Answers2

1

Someone else committed (and pushed) changes to the main branch. So as suggested you can first pull to merge the new changes into yours OR rebase before pushing OR force push (that will destroy someone else's changes though.

For more info and a graphical representation of what happened take a look e.g. here: https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

Gameplay
  • 1,142
  • 1
  • 4
  • 16
0

It seems your main branch has been changed. So you need to pull the changes to your local repo. You can follow the below solutions-

  • Fetch the remote repository’s copy of the current branch, then merge-
    $ git pull

or,

  • Pulls the commits from the origin/main and applies your changes upon the newly pulled branch history-
    $ git pull --rebase origin/main

Then push your changes to the remote repo.