[SOLVED !] CLI: "git reset --hard HEAD~2" worked OK, now how to push to GitHub ?

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
sebastjava
Level 5
Level 5
Posts: 713
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

[SOLVED !] CLI: "git reset --hard HEAD~2" worked OK, now how to push to GitHub ?

Post by sebastjava »

I am currently just doing some experiments on my ~/hello-world repo before doing some more serious things on another repo of mine...

So, I have a repo with 2 branches. I want my master branch to remain virgin, without any commit except the initial one. Being perfectionist, i don't want to just revert to the initial files while keeping a messy, 3 commits log. So i did this:

Code: Select all

git reset --hard HEAD~2
That's simple, easy to understand, and... it worked! Now, when i look at this ~/hello-world working directory, i only have the files i had on the initial commit. And... when i look at the git log, now i only have my initial commit showing there. My bad history got erased. That is exactly what i wanted. Just a pure 2X "undo", going 2 commits behind.

OK, now here is the problem. I tried a simple git push to push this to GitHub. But i get this error message:

Code: Select all

error: failed to push some refs to 'https://SebastJava@github.com/SebastJava/hello-world.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.
Noooo! I don't want to pull all this junk from my GitHub repo. I just want to do this same git reset --hard HEAD~2 on GitHub.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
User avatar
sebastjava
Level 5
Level 5
Posts: 713
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

Re: CLI: "git reset --hard HEAD~2" worked OK, now how to push to GitHub ?

Post by sebastjava »

Code: Select all

git push --force
That was all i needed! The simpler it is, the less risk there is of making mistakes. :)
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
Locked

Return to “Software & Applications”