Configuring Sourcetree Push for Gerrit

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

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" ?

 

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?

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.

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.

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?

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?

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.

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

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.

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.

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.

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. :(

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

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

Suggest an answer

Log in or Join to answer
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

276 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot