Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push current branch to Gerrit

Tags:

git

gerrit

I like to use simply git push to push (only) the current branch to the configured upstream. For that I set git config push.default upstream which does exactly the right thing.

Now I tried to set up a a suitable remote for Gerrit, which automatically pushes to refs/for/*.

The idea was doing it this way:

[remote "gerrit"]
        url = ssh://host:port/repo
        push = refs/heads/*:refs/for/*

I would like to type git push gerrit and expect git to push only the current branch to the correct ref.

Unfortunately now git tries to push all local branches to Gerrit. - Is there any way to tell git to push only the current branch like with the push.default above?

Update:

  • Git push can only use a single refspec.
  • If an explicit refspec is given on the command line this one is used.
  • If none is given on the command line, the one defined with the remote is used.
  • If none is given with the remote, too, only then push.default is considered.

For Gerrit I need a refspec like 'branch:refs/for/branch' with branch being the current branch.

Question:

  • Is there an explicit refspec equivalent to what push.default=upstream is doing?
  • Is there a way to configure git to make a plain git push automatically push to the correct refs/for ref?

Currently the best way I found is wrapping everything in a separate script like suggested here. But I am still not convinced that it is not possible with just a suitable refspec.

like image 320
michas Avatar asked Jan 14 '13 14:01

michas


1 Answers

According to the source, Git currently implements push.default = upstream by generating an explicit refspec containing explicit names.

Seems like there is currently no way to specify that behavior by a single generic refspec, and some script (like suggested here) which builds an explicit refspec is the only way for now.

like image 192
michas Avatar answered Oct 19 '22 00:10

michas