Skip to content
Discussion options

You must be logged in to vote

🛠️ Fixing a Detached HEAD Commit in Git

📘 Problem

You made a commit while in a detached HEAD state and pushed it to origin/master, then tried merging it into master, but faced too many conflicts.

Now, you want to:

  • Keep that latest commit
  • Force it to become the new state of master
  • Discard the current state of master and its conflicts

✅ Solution: Force master to Match Detached Commit

⚠️ This will overwrite the current master branch. Make sure this is what you want.

🔁 Steps

# Step 1: Checkout to master
git checkout master

# Step 2: Reset master to the detached commit
git reset --hard localNet     # or use commit hash

# Step 3: Push the changes forcefully to GitHub
git push origin mast…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by kmchen13
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants