Coding⏱️ 2 min read📅 2026-05-30

How to Fix: Git push error '[remote rejected] master -> master (branch is currently checked out)'

Quick Answer: When pushing to a remote repository, make sure you are not on the master branch. Use 'git checkout main' or 'git checkout develop' instead.

When you attempt to push changes from a checked-out branch, Git will reject the push due to the branch being currently checked out. This is because Git requires the branch to be in a clean state before allowing pushes.

✅ Best Solutions to Fix It

Method 1: Switch to a Different Branch

  1. Step 1: Run the command git checkout -b new_branch to create a new branch, or switch to an existing one with git checkout existing_branch.

Method 2: Use the --force Option (Not Recommended)

  1. Step 1: Run the command git push -f origin master, but be aware that this will overwrite any existing commits on the remote repository.

🎯 Final Words

To avoid this issue in the future, always switch to a different branch before making changes and pushing them up. Alternatively, you can use the --force option with caution.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions