All guidesDeveloper tools & APIs
Developer tools & APIs

Fix GitHub Repository Initialization Errors

Resolve GitHub initialization conflicts by checking the remote README or license before the first push.

Related brands
GGitHub
Category
Developer tools & APIs
Official sources
2
Read time
5 min
Last checked
2026.09.24
ANSWERGitHub repository initialization errors primarily occur when automatically generated README.md or LICENSE files in the remote repository conflict with local commits. Resolve by first fetching the remote commit history and merging it locally, or by resetting the local commit state. git pull origin main --allow-unrelated-histories

What non-fast-forward and unrelated histories errors mean

GitHub Docs product screen relevant to this step
Create a repo

When creating a repository via the GitHub web UI with README.md, .gitignore, or LICENSE files specified, attempting to force-push local commits results in a [rejected - non-fast-forward] or fatal: refusing to merge unrelated histories error.

This occurs because the remote repository already contains an initial commit that is not connected to the local commit's ancestor.

This conflict appears when the repository was created on the web with a README, .gitignore or license and a separately initialized local commit is then pushed to it. Before proceeding, run git status and git remote -v in the command line to verify the remote URL connection and the list of currently staged files.

Causes by Terminal Message

Accurately identifying the primary cause of the error prevents unnecessary commit loss. Compare the messages currently output in your terminal against the status table below.

Terminal Error MessagePrimary CauseCheck ItemAction Direction
fatal: refusing to merge unrelated historiesAttempt to merge two repositories with different commit historiesCompare local/remote commit trees with git logUse --allow-unrelated-histories flag
error: failed to push some refs toRemote repository contains latest commits not present locallyCheck remote changes after git fetch originApply git pull or rebase then push
fatal: remote origin already existsA different remote URL is already registered as originView registered URL with git remote -vRe-register with git remote remove origin
error: src refspec main does not match anyNo committed history locally or branch name differsCheck current branch name with git branchCreate git commit or change branch name

From git status to a Successful Push

The following step-by-step procedure safely synchronizes the remote repository's initial files with the local project and resolves push errors.

  1. Open a command-line terminal in the local project's root directory and run git status to check the status of untracked files.
  2. If the current directory lacks a local Git history, run git init to initialize the repository and run git branch -M main to set the default branch name to main.
  3. Run git remote add origin https://github.com/username/repository.git to connect the GitHub remote URL to the local repository.
  4. Run git pull origin main --allow-unrelated-histories to merge the remote repository's README.md and LICENSE commits into the local repository.
  5. If conflicts occur, edit the indicated files per terminal guidance, then run git add . and git commit -m "Fix merge conflict" to complete the commit.
  6. Run git push -u origin main to push all local branch history to the remote repository.

Output and pages that confirm the push worked

Upon completion of the recovery procedure, the terminal displays Everything up-to-date or branch 'main' set up to track 'origin/main'. The presence of this message indicates that the branch tracking relationship between local and remote is fully established.

Access the GitHub repository URL in a web browser and refresh. If the locally created files and the README.md added via the web UI appear sequentially in a single commit list, initialization is complete.

Checking permissions and contacting GitHub Support

If pushes continue to be rejected due to network access permissions or organization policies, an account permission review is required. When logged in with an organization account, first check the repository creation and push permission policies in the admin console.

If the issue persists and a GitHub Support ticket is filed, provide the full error log, the output of git remote -v, and the Git version in use. For a new project where commit history need not be preserved, delete the local .git folder and use the GitHub Desktop application's Clone repository menu to re-clone the repository as an alternative path.

Revision history · 2026-09-24

This article was revised against the provider’s official documentation. Korean note

Sources

docs.github.com — Quickstart for repositories (2026-08-19)

docs.github.com — Create a new repository (2026-08-19)

Open provider document
Next guideOpenAI API Pricing: Calculate Cost and Check Usage Limits