1

How to configure Git so that when I do git push it automatically does this:

git push origin master:something_else

There are question on how to do this manually:

But how to have Git do this automatically?

I've tried the --set-upstream-to option but that only affects pulling.

laggingreflex
  • 32,948
  • 35
  • 141
  • 196

1 Answers1

2

https://git-scm.com/book/en/v2/Git-Internals-The-Refspec#_pushing_refspecs

Pushing Refspecs

It’s nice that you can fetch namespaced references that way, but how does the QA team get their branches into a qa/ namespace in the first place? You accomplish that by using refspecs to push.

If the QA team wants to push their master branch to qa/master on the remote server, they can run

$ git push origin master:refs/heads/qa/master

If they want Git to do that automatically each time they run git push origin, they can add a push value to their config file (/.git/config>):

[remote "origin"]
    url = https://github.com/schacon/simplegit-progit
    fetch = +refs/heads/*:refs/remotes/origin/*
    push = refs/heads/master:refs/heads/qa/master

Again, this will cause a git push origin to push the local master branch to the remote qa/master branch by default.

laggingreflex
  • 32,948
  • 35
  • 141
  • 196
  • 2
    Yes, that is the way to do it - question was not quite clear : ). I think you can do this on the command line if you wanted to automate it, somthing like: `git config remote.origin.push = refs/heads/master:refs/heads/qa/master`, not quite sure the syntax on that one, so check it first :o ... this overrides the git push.default – code_fodder Apr 22 '18 at 19:43