Lesstep
Forgejo · Gitea · Codeberg · git over HTTPS · Checked November 22, 2026

git push: "fatal: Authentication failed" on Forgejo, Gitea and Codeberg

Git prints fatal: Authentication failed when the server answers 401 to a push or clone over HTTPS. The line above it, which starts with remote:, is the server's own reason. With two-factor authentication on, a password does not work for Git over HTTPS at all: create an access token and give it to Git as the password. The same applies when the saved login is old or was made by a credential manager.

The two messages

A dry-run push to codeberg.org with a user name and password that do not exist (November 22, 2026) prints:

remote: Credentials are incorrect or have expired. Retry your command or see https://codeberg.org/forgejo/forgejo/issues/2809 for more information
fatal: Authentication failed for 'https://codeberg.org/forgejo/forgejo.git/'

The source code of Forgejo (routers/web/web.go, string unauthorized_credentials) sends this text for any login to the Git endpoint that the server rejects. The second message is in routers/web/repo/githttp.go of Forgejo, and in the same file of Gitea. Both answer 401 when the user has two-factor authentication and signed in with a password:

Users with two-factor authentication enabled cannot perform HTTP/HTTPS operations via plain username and password. Please create and use a personal access token on the user settings page

A comment in the Forgejo file says this answer may later be replaced by "invalid credentials", so a server may show the first message to a 2FA user. Which of the two a 2FA account sees is not stated in the source. The fix is the same.

To see the server's text without Git, ask the same address with curl (replace OWNER/REPO):

curl -i -u "USER:PASSWORD" "https://codeberg.org/OWNER/REPO.git/info/refs?service=git-receive-pack"

For pull requests inside the IDE: Pull Request Inbox for Forgejo and Gitea, a plugin for JetBrains IDEs, keeps one token for Codeberg and one for your own server, each sent only to its own server, and on a 401 says that the server rejected it and shows the server's message.

What the official pages say

The Codeberg documentation on 2FA says that pushing over HTTP needs a personal access token, that the token replaces your normal password plus authentication code, and that Git asks for the user name and then takes the token where it asks for the password. It shows no error text. Forgejo issue #2809 is where the "Credentials are incorrect or have expired" text points. It reports that the first push over HTTPS fails and the second works when git-credential-manager is used, and a maintainer there recommends a personal access token with limited permissions, or SSH.

Fix it

  1. Your avatar, Settings, Applications, and under Access tokens create a token. For Git it needs the repository permission: read to clone, read and write to push (the server checks the token's repository scope for the access the command needs; which scope groups exist).
  2. Copy the token. Codeberg's page says it is not shown again.
  3. Remove the old login that Git or your OS saved for this host. Otherwise Git keeps sending it. The git credential manual says to use the reject action for a login the server refused, which removes it from the credential helper:
    git credential reject
    protocol=https
    host=codeberg.org
    
    Finish the input with an empty line. Use your own server's host name instead of codeberg.org.
  4. Push again. At Username for 'https://codeberg.org': type your user name, and at Password for ... paste the token.

SSH needs no token and no 2FA code; see "Permission denied (publickey)".

Forgejo and Gitea pull requests in IntelliJ IDEA

Pull Request Inbox for Forgejo and Gitea, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, keeps one token for Codeberg and one for your own server, each in the IDE's password safe and sent only to its own server. Without a token it reads public repositories; for a private one it says that it needs an access token. When the server refuses a token with 401, the plugin says that the server rejected it (expired or deleted, or from another server), shows the server's message, and offers to open its settings, which link to your server's token page. Reading is free; approving, commenting and merging are Pro (US$1.50 a month, with a 30-day trial).

Get it on JetBrains Marketplace

Forgejo, Gitea and Codeberg are names of their respective owners; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by the Forgejo project, Codeberg e.V., the Gitea project or JetBrains.

More: 401 "token is required" and the unknown-token messages · "token does not have at least one of required scope(s)" · Forgejo and Codeberg SSH "Permission denied (publickey)" · Git "self-signed certificate" on your own Forgejo or Gitea · 404 "The target couldn't be found." and "not found" · Forgejo and Gitea pull request not created (409, 422, 403) · Forgejo and Gitea merge refused (405, 409) · Forgejo and Gitea pull request plugins for IntelliJ IDEA, compared · 日本語