0

I have a file on Github that I want to update, as I have added new stuff to my local file. I did the git add, commit, & push origin master. The add & commit worked fine but push origin master is not working.

This is what I get when I try to do push origin master:

    $ git push origin master
    To https://github.com/AhmaadJ/ChatBot-Lite.git
     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'https://github.com/AhmaadJ/ChatBot-Lite.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.

I did git pull, than did some stuff that I also found online for similar problems, & I got a merge conflict. I aborted the merge, & checked the status, log, & remote to see what is the problem.

Here's what status brought up:

    $ git status
    On branch master
    Your branch and 'origin/master' have diverged,
    and have 3 and 3 different commits each, respectively.
      (use "git pull" to merge the remote branch into yours)

    nothing to commit, working tree clean

Should I undo my latest commit? If so, how?

I'll also link pictures of the code below:

Pictures Contain:

-Drawing Diagram

-Pull, Branch, Merge Abort

-Log, Status

-Log, Pull, Status

-Status, Log, Branch, Remote -v

Images Files changed within the commit

  • You probably want to rebase your changes instead of merging. Please post a graph diagram of the origin and local branches. – Dai Jan 26 '20 at 01:01
  • @Dai I posted a diagram of the branches in the link – ASJackson923 Jan 26 '20 at 01:09
  • Did you clone an empty repo? Git doesn't think your local repo and the remote repo share any common history. – user229044 Jan 26 '20 at 01:12
  • Does this answer your question? [master branch and 'origin/master' have diverged, how to 'undiverge' branches'?](https://stackoverflow.com/questions/2452226/master-branch-and-origin-master-have-diverged-how-to-undiverge-branches) – phd Jan 26 '20 at 01:18
  • https://stackoverflow.com/search?q=%5Bgit%5D+Your+branch+and+%27origin%2Fmaster%27+have+diverged – phd Jan 26 '20 at 01:18
  • @user220944 No, I didn't clone. This is my own repo that I added and that I am using. – ASJackson923 Jan 26 '20 at 01:48
  • @Dai & after I rebase will pushing to origin master work? – ASJackson923 Jan 26 '20 at 02:44
  • @ASJackson923 Yes, provided you rebased on-top of `origin`'s `HEAD` (i.e. you pulled first). – Dai Jan 26 '20 at 02:55
  • @Dai Is doing a reset (soft, mixed, or hard) to the commit before by most recent one & than restarting better or is it best to use the rebase? I provided the log stat & reflog in my second link so you can see what else it says I just wanted to add the V2 file & the CSS file to the repo (updating the old file with the new file containing the 2 files+what was in the old file) – ASJackson923 Jan 26 '20 at 04:45
  • @Dai It gives me this when I rebase: $ git pull --rebase First, rewinding head to replay your work on top of it... error: The following untracked working tree files would be overwritten by checkout: CBL Pictures/Screenshot (555).png CBL Pictures/Screenshot (556).png CBL Pictures/Screenshot (557).png CBL Pictures/Screenshot (558).png CBL Pictures/Screenshot (559).png CBL Pictures/Screenshot (560).png CBL Pictures/Screenshot (561).png Please move or remove them before you switch branches. Aborting could not detach HEAD – ASJackson923 Jan 27 '20 at 02:11
  • @phd somewhat, I did that but I still get this message: $ git pull --rebase First, rewinding head to replay your work on top of it... error: The following untracked working tree files would be overwritten by checkout: CBL Pictures/Screenshot (555).png CBL Pictures/Screenshot (556).png CBL Pictures/Screenshot (557).png CBL Pictures/Screenshot (558).png CBL Pictures/Screenshot (559).png CBL Pictures/Screenshot (560).png CBL Pictures/Screenshot (561).png Please move or remove them before you switch branches. Aborting could not detach HEAD – ASJackson923 Jan 27 '20 at 22:59
  • @meagar This was my problem all along lol. I forgot to clone to my repo before add, commiting, & pushing. I took a long brake from this lol & finally fixed it last week. Thanks! – ASJackson923 Apr 03 '20 at 22:07

0 Answers0