Problem
A push from Git | Push in IntelliJ IDEA (or another JetBrains IDE) shows a notification that the commits were pushed. A second push reports that the branch is up to date. The branch on the remote does not contain the commits: GitHub, a Git GUI client, and git status in the terminal all show the branch as not pushed.
This happens in every repository on the machine, not only in one project.
The idea.log file shows that the push goes to refs/for/main instead of to the branch of the same name:
git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/feature-branch:refs/for/main
To https://github.com/example/repository.git
* refs/heads/feature-branch:refs/for/main [new reference]
Cause
The Git configuration contains a push refspec for the origin remote that targets the Gerrit review ref refs/for/main, for example:
[remote "origin"]
push = HEAD:refs/for/main
This is a Gerrit (code review tool) setting: Gerrit turns a push to refs/for/<branch> into a code review. When the entry is in the global ~/.gitconfig, it applies to every repository whose remote is named origin.
The IDE uses the remote.<name>.push refspec as the default target in the Push dialog, so every push goes to refs/for/main. A Git host that is not Gerrit accepts the push and stores refs/for/main as a separate ref. It is not a branch, so it does not show in the branch list, and the branch itself does not change. A plain git push in the terminal uses the same refspec.
Resolution
-
In the terminal, open one of the affected repositories and run:
git config --show-origin --get-all remote.origin.pushThe output names the file that holds the setting, for example:
file:/Users/user/.gitconfig HEAD:refs/for/main -
If the file is the global
~/.gitconfig, remove the entry:git config --global --unset-all remote.origin.pushIf the file is the repository's
.git/config, run the same command inside the repository without--global. -
Push from the IDE again. The Push dialog now proposes the upstream branch, or a new branch with the same name as the local branch, and the commits reach the remote.
If some repositories use Gerrit and need the refspec, set it only in those repositories. Run this command inside each Gerrit repository, with the review branch in place of main:
git config remote.origin.push HEAD:refs/for/main
As a one-off workaround without changing the configuration, click the target branch name in the Push dialog and change it to the branch name before pushing.
The extra refs/for/main ref stays on the remote after the fix. It does not affect the branches.
Comments
0 comments
Please sign in to leave a comment.