-2

So, simply explaining my current situation:

  • I kept pushing changes into origin master (no branches made yet)
  • I decided to change the commit message of the initial commit of the Github Repository
  • I did $ git rebase -i --root and change the commit message successfully
  • I tried to force push by doing $ git push --force, but to get the following error:

    fatal: The current branch master has no upstream branch.  
    To push the current branch and set the remote as upstream, use 
    
    git push --set-upstream origin master.
    
  • I tried to follow the instruction, but to get:

! [rejected]        master -> master (non-fast-forward) error: failed
to push some refs to 'git@github.com:BLAHBLAH.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.

What am I doing wrong?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
JiHo Han
  • 11
  • 4
  • Does this answer your question? [Change first commit of project with Git?](https://stackoverflow.com/questions/2246208/change-first-commit-of-project-with-git) – Grigory Kislin Apr 21 '23 at 10:21
  • Duplicated, see https://stackoverflow.com/questions/2246208/change-first-commit-of-project-with-git https://stackoverflow.com/questions/2119480/edit-the-root-commit-in-git – Grigory Kislin Apr 21 '23 at 10:22

1 Answers1

0

If you are only trying to modify the last commit - use ammend

# Change the latest commit message
git commit --amend --no-edit -m"<new message>

To push your changes:

Use this command:

# It will set up the "track" and will force the push
git push --set-upstream origin master -f

enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167