Configuring Sourcetree Push for Gerrit

Mark Harrop
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 12, 2012

Hi,

I'm trying to replicate the following command (which works from command line) in sourcetree

git push http://<username>@repo.xxxxx.com/gerrit/p/puppet_tate HEAD:refs/for/master

How do I get sourcetree to pass the bit in bold - it seems to only want to push with master:master appended

I've tried to manually overtype the name of the remote branch to refs/for/master which seems to get me halfway there,
(log shows push to master:/refs/for/master)
but can't get the HEAD into the command (instead of master)

Any clues?
Thanks

8 answers

3 votes
Greg Bentz
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 27, 2015

I am using SourceTree for Mac, version 2.0.5.2

I can get the "Custom Action" to work, so I have a path forward.  Albeit, less than graceful.

I am trying to use this suggestion:

git config remote.origin.push 'refs/heads/*:refs/for/*'

I find that it fails for me.  The dialog shows that the command is expanding to:

git push -v origin refs/heads/master:refs/heads/refs/for/master

This is almost right, except that the extra "refs/heads/" after the colon gets in the way.  It makes me think there is an issue in how the destination of the push is being expanded.

Any advice on how to formulate the git configuration, so that the push action will produce a destination of ":refs/for/master" ?

 

0 votes
vossbot February 17, 2014

To solve this i have add a custom action in Tools-Options, then select "Custom Actions" tab here you can add you custom command.
we have 1 for pushing refs/for/develop configured like this.

"Script To run" cmd

Parameters: /c git push origin $SHA:refs/for/develop

Then you can rightclick on the commit and push it for develop

0 votes
rehanahmad
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 16, 2013

An easier solution could be to have custom buttons for the custom actions. This would solve many other similar problems.

0 votes
Rainer Burgstaller October 30, 2013

Hmm, am on SourceTree 1.7.3 and I have done

git config remote.origin.push 'refs/heads/*:refs/for/master'

However, now when I right click on a branch and try to select "Push To" then the popup is empty. When I simply press the push button, then it changes the remote to "custom" and the branch is still master:master.

If I try

git config remote.origin.push 'refs/heads/*:refs/for/*'

then it will push master:master. So no joy. :(

0 votes
Douglas Ferguson July 1, 2012

OK.. I looked into setting up a custom action.

The problem is that this command is buried beneath menus, it this case it is easier just to use the command line.

Also, the thing I liked about using source tree was that I could push at the same time as commiting, it would be nice to override the default push command used by the push button at the top and the push command in the commit window.

At some point I was able to get src tree to push, but I think it mst have went to a branch that gerrit could not see or wasn't expecting.

0 votes
Douglas Ferguson June 29, 2012

I'm having problems using source tree to push to gerrit.

I can push from the commandline just fine, but when I push from source tree I get the following:

! [remote rejected] master -> master (can not update the reference as a fast forward)

This is in my git config

[remote "gerrit"]

url = ssh://gerrit/XXXXX
push = HEAD:refs/for/master

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 1, 2012

SourceTree 1.4 handles gerrit pushing configured as "refs/heads/*:refs/for/*" (this was raised above and has since been addressed) but currently not specifically from HEAD. This is because the git push dialog is designed to push branches, not HEAD.

You have two options right now - either use the wildcard version of the push mode to gerrit, or alternatively create a Custom Action which performs a parameter-less push which will respect your existing configuration. You can do that on the Preferences / Custom Actions page, just entering a command of 'git' and a parameter of 'push gerrit', then you can invoke this to perform your HEAD push if you want.

Douglas Ferguson July 1, 2012

OK.. I looked into setting up a custom action.

The problem is that this command is buried beneath menus, it this case it is easier just to use the command line.

Also, the thing I liked about using source tree was that I could push at the same time as commiting, it would be nice to override the default push command used by the push button at the top and the push command in the commit window.

At some point I was able to get src tree to push, but I think it mst have went to a branch that gerrit could not see or wasn't expecting.

0 votes
Jonathan Borden
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 27, 2012

I understand that you can overtype the remote branch. how do you make this persist so you don't have to keep entering the remote branch on the push dialog?

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 27, 2012

At the moment SourceTree doesn't provide a GUI option to set this, but if you configure it on the command line SourceTree will pick it up as of 1.3.2+. You do this via a command like this:

git config remote.origin.push refs/heads/*:refs/for/*

That's a Gerrit example, but you can use a similar approach to push differently by default. The tracking branch in Git is only used for pulling, which is Git standard behaviour and which SourceTree conforms to, but there are discussions about unifying this in future, see https://jira.atlassian.com/browse/SRCTREE-938 - we'll be led by what git does here so as not to be inconsistent.

0 votes
stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 12, 2012

Hmm, yes at the moment you can only push a local branch to a remote branch. You can name the remote branch anything you like, but you can't pull in a local reference other than a local branch.

I take it then that HEAD is detached in your case? Is there any reason why you don't create a local branch to 'solidify' that HEAD?

Rainer Burgstaller February 14, 2012

Gerrit does not work like that. refs/for/master is not a real branch that you can track locally. It is a handle that will be used to create virtual review branches that are invisible from the outside. Therefore that does not easily work.

I too have the same problem that I cannot properly work with gerrit. I tried to configure a remote with HEAD:refs/for/master but when I push my local changes it ends up going straight to master.

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 14, 2012

You can definitely overtype the remote branch and set that to /refs/for/master. So long as you have a local branch you can push that to /refs/for/master and that's exactly the same as pushing HEAD:/refs/for/master, assuming that your HEAD is also on your branch. Git only uses the left side of the push ref to identify what to push, it doesn't matter what it's called, HEAD and master will refer to exactly the same commit if you're on the master branch locally.

You can probably get this defaulted if you click the 'Track' option on the push dialog, unless what gerrit is doing is completely invalid for git. If it is, there's not much I can do about that and you'll just have to overtype the remote column each time.

PZ
Contributor
May 26, 2016

Are there any news 4,5 years later? At least putting my custom action in the toolbar?

 

Ticking the "Track"-Option doesn´t work unfortunately. I always have to enter the "refs/for/master/" manually. :-/

Isn´t there a way to save this like Tortoise-Git does?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events